I have 12+ divs with different id’s that I want to all change their text color on button click. I would like to use the getelementsbyname but it isn’t supported. Whats the least cumbersome way to select all these divs?
@Fly_MoeApr 19.2007 — #I have 12+ divs with different id's that I want to all change their text color on button click. I would like to use the getelementsbyname but it isn't supported. Whats the least cumbersome way to select all these divs?[/QUOTE]
Use getElementById. Do a search online on how to use it. If you have problems come back here with your questions.
@aj_nscApr 19.2007 — #I had a similar situation to this...I did something like this. I can't take credit for it, I picked up the idea somewhere online but I can't remember where:
Keep in mind you can do this with a whole host of tags (using getElementsByTagName) and whatever attribute you want.
P.S. I'm not sure if the color = "#000000"; is the Javascript equivalent to the proper CSS, but you get the picture. It's an excellent little snippet, though, don't you think?
@toicontienApr 20.2007 — #The name attribute is deprecated in HTML now. Use the class attribute instead, and then use this script: document.getElementsByClassName = function(c) { var els = [], found = []; if (document.getElementsByTagName) { els = document.getElementsByTagName('*'); for (var i=0, end=els.length; i<end; i++) { if (els[i].className === c) { found.push(els[i]); } els[i] = null; } } return found; };
function lehula() { var divs = document.getElementsByClassName('changeDIV'); var arr = ["red","aqua","green","yellow","orange","turquoise","pink","blue","coral","maroon","olive","navy"]; for (var i=0, end=divs.length; i<end; i++) { divs[i].style.color = i > 0 ? arr[i-1] : arr[arr.length -1]; } } All of your DIV tags should be like this: [code=html]<div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div> <div class="changeDIV"></div>[/code]
I had tried for a script of selecting the content inside the div tag. there i used getElementByName to get the contents of div tag. I dont know whether it is workable or not.. can anyone put me in right way
I used the function as
[CODE] function SelCon() { document.getElementByName("testarea").select() } [/CODE]
I have div tag as [CODE]<div class="copycon" name = "testarea">[/CODE]
But i cant get the result what i want... Will getElementByName will get the values of div by name???.....Any valuable suggestions pls....
@FangApr 21.2007 — #If you only have one div with that name:document.getElementByName("testarea")[0].select() [I]getElementByName[/I] returns an array.