Quantcast
Channel: Changing the ID of all "div" elements (Javascript) - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by Bergi for Changing the ID of all "div" elements (Javascript)

function setIDs() { var divs[] = new Array(); // no need for an extra array. Invalid identifier, btw. for(i in document.getElementsByTagName('div')) // never run through Arrays with for-in-loops. It's...

View Article



Answer by Simon for Changing the ID of all "div" elements (Javascript)

Can you use jQuery? If so, you should try something like this:var x = 0;$("div").each(function(){ $(this).attr("id", "child"+x); x++;});

View Article

Answer by Alexander for Changing the ID of all "div" elements (Javascript)

Don't use for...in and reuse document.getElementsByTagName result.function setIDs() { var divs = document.getElementsByTagName('div'); for(var i=0; i<divs.length; i++) { divs[i].id = "child"+ i; }}

View Article

Answer by user1106925 for Changing the ID of all "div" elements (Javascript)

Invalid JavaScript. var divs[] = new Array();Also, do not use for-in for Array or Array-like iteration. It will often fail.

View Article

Changing the ID of all "div" elements (Javascript)

As the title says, I'm trying to change the ID of all elements with the tag "div". Here's my current script, which does not work:function setIDs() { var divs[] = new Array(); for(i in...

View Article

Browsing all 5 articles
Browse latest View live




Latest Images