SetAttribute + IE 6
Apr 6, 2007
this script updates an image on a page and resets the class name of a link. Works fine in Mozilla browser. However, the setAttribute method in the second function doesn't work in IE. Is there a known bug connected with this?
Any ideas?
var view;
//update image
function getView(view)
{
var source = view.getAttribute("href");
var imgsrc = document.getElementById("view");
imgsrc.setAttribute("src", source);
setClass(view);
}
// update class names of links
function setClass(view)
{
var arLinks = document.getElementsByTagName("a");
var ct = (arLinks.length-1);
for (var i=0; i<ct; i++)
{
arLinks[i].setAttribute("class", "inactive");
}
view.setAttribute("class", "active");
}
View 3 Replies
ADVERTISEMENT
Jul 23, 2005
I am struggling to write an meta element in JS. The meta element in question
is the refresh element.
This is the code I am using
//----------------
function setMetaContent(metaTag, metaName, value) {
//----------------
var metas = document.getElementsByTagName('meta');
if (debug) alert('[setMetaContent] metaTag='+metaTag+' metaName=
'+metaName+' value '+value);
for (var i=0; i<metas.length; i++) {
if (metas[i].getAttribute(metaTag)==metaName)
break;
}
if (debug) alert('[setMetaContent] i='+i+' value '+value);
metas[i].setAttribute('content',value);
}
and I call it with:
View 7 Replies
View Related
Nov 24, 2011
How do I use a variable in setAttribute ?
View 1 Replies
View Related
Mar 27, 2005
I'm in the process of migrating a script to use DOM core methods but I've hit a roadblock in the aforementioned browser. The following code snippet illustrates what I'm basically trying to do, it really is incredibly basic!
var newimg = document.createElement('img');
newimg.setAttribute('id', 'placeholder');
newimg.setAttribute('src', 'images/large/courtyard.jpg');
I'm then positioning the element on the page using appendChild(). Everything works perfectly on Firefox 1, IE5+, Opera 8, Konqueror 3.3.1 (Linux) but not in Opera 7.54. I suspect the element is being created as associated styling on #placeholder is being applied (just some padding and borders) but the image itself is not being displayed. I assume therefore that the problems lies with setAttribute()?
This seems like the sort of problem that others would have encountered, but I haven't been able to find mention of it anywhere.
View 7 Replies
View Related
Oct 7, 2005
I did some searching around, but didn't see this addressed directly. Here is an example of when dot notation fails in Firefox, and when SetAttribute doesn't fail: Code:
View 4 Replies
View Related
Jul 31, 2006
this works perfectly in firefox - but in internet explorer it just creates the first lable and the input field, although it creates the input field as a regular text field instead of for files. the caption label and text field aren't created at all. any ideas? Code:
View 7 Replies
View Related
Dec 10, 2006
I am using the following code to create an 'a' element with 'texto' to add the onclick property to an object:
var vinculo = xCreateElement('a');
var nodoTexto = document.createTextNode('texto');
xAppendChild(vinculo, nodoTexto);
xAppendChild(celda2, vinculo);
vinculo.setAttribute('onclick', 'buscarSolucion(1,1,1)');
'celda2' is a table cell. This works with FF but not with IE. I solved this using a comment from here for the 'name' attribute, like this:
...
vinculo = xCreateElement('<a onClick="' + onClick + '">');
...
But I would like to put it in a function to make it general for any element that has the 'onclick' property. Is there any other way to set the 'onclick' attribute & to be understand by IE & FF?
NOTE: I also found that I can not set 'colspan', I have to set colSpan. Also, I can not set 'class' I have to use the canonical method with 'object.className=...'
View 10 Replies
View Related
Nov 18, 2007
I know there is a problem with IE (I wont bother inserting a witty comment here) on handling:
setAttribute('onclick','doStuff');
I have found
yourAnchor.onclick = function() {
// do what you want in here.
}
this works, but I the script I am working on is going through every DIV with a certain class and adding links to the div, I want the button to change something within the div where it is located so I need to pass the id of the parent div. I thought perhaps there was someway to find the id of the button pressed?
View 5 Replies
View Related
Nov 15, 2010
Just after upgrading from v1.4.3 to v1.4.4 I started receiving this javascript error on the console, but apart from the update, I didn't do any code modifications. If I follow the console link, it takes me to this point in the source:
[Code]...
with the line in red marked as the error source. What could it be causing the error?
View 8 Replies
View Related
Sep 23, 2009
Im writing a piece of javascript that dynamically adds a link to a page, this is the code i'm using
var newP;
newP = document.createElement("a");
newP.innerHTML = "Click here";[code].........
However, it wont work?!?! the link appears in the right place on the page when i remove the line newP.setAttribute("href","http:[url]......);and if i view the source the link is <a>Click here</a> (without any href) so there's got to be something wrong with that line but i don't know what it is.I'm using firefox.
View 2 Replies
View Related
Jan 7, 2007
It works OK in IE and Moz, but in Opera the change of the attribute's value works on once, first time. No error. That confuses me. Why works only once? Any ideas? Code:
View 16 Replies
View Related
Jul 18, 2007
I have multiple attributes (class, id and title) that is needed to insert into a div together. All I know how to use setAttribute for single attribute. So the question is there an "array" setAttribute method to insert all attributes together into an element OR is there a "after" or "before" setAttribute method I can use to insert an attribute after or before other attribute?
View 2 Replies
View Related
Mar 19, 2009
I want to implement:
<a href=123 onclick="javascript:return false">123</a>
in DOM,
I have:
var link = document.createElement('a');
link.setAttribute('href', 123);
link.setAttribute('onclick', 'function() { return false; }');
but it doesn't work. The reason I want a href and onclick = false is because I want to drag and drop the 123.
View 2 Replies
View Related
Jun 26, 2002
I need setAttribute "src" from main windows to pop-up window (Iframe in it) and also i need to prepload all src files ONCE, so if user ever click to open pop-up and do it againt, its no need to loading againt, can anybody help with the script ... ? Or maybe can sugest me with better method to have same result.
View 3 Replies
View Related
May 10, 2011
I've been working on this for about four hours (two today, two yesterday) and keep hitting the brick wall. I'm trying to create a function that will add an attribute to specified tags. As the title says, it works great in FF and not at all in IE7. Probably the first question you'll ask after you see my code is "why?" Well, I've got a form with over 100 form fields in it, and if I can avoid manually adding an attribute to all of them, I'll take the JS route.
[Code]...
View 5 Replies
View Related
Jan 26, 2010
I am trying to setup a form with radio buttons. Each radio button has an OnClick event. When a radiobutton is clicked the current set of radio buttons will be replaced with a new set using document.createElement("input"). Each new radio button needs the same onclick event addedas in the initial set of radio buttons. I first tried:
element.setAttribute('onclick', MyFunction(value));
This, however, will somehow automatically trigger the onclick event! I searched on the internet and found this as the solution:
var new_onclick = function() { alert("this works!"); };
element.setAttribute('onclick', new_onclick);
This will give a "Object" is undefined error!
View 2 Replies
View Related
Feb 24, 2010
Is the form below a valid method of changing the id of an XHTML element, specifically the one actually being referenced? It does not seem to work for me.
document.getElementById("Original_Name").setAttribute("id", "New_name");
View 4 Replies
View Related