<script type="text/javascript">
function retract() {
document.getElementById("ret-banner").id = 'exp-banner';
}
function expand() {
document.getElementById("exp-banner").id = 'ret-banner';
setTimeout('retract()', 3000)
}
</script>
but i need it to get the element by class instead. I tried just by changing it to document.getElementByClassName but it didnt work. Why? Could you please give me some ideas?
this is an alternative way to do it BUT with a click event as mouse over is worrisome..
This uses the new classList that is supported in all new browsers now.
if you require backward compatibility then add the work around. (homework for you).
you can still use the *mouseover* event instead of the *click* event if you add/remove the event as I have done with the click event in the alternative versions..
just replace the string *click* with *mouseover* in each ***addEventListener*** and of course the ***removeEventListener***
I am getting to old for this...
Last edited by grumpyOleMan; 02-14-2013 at 07:33 PM.
thank you for your responses. Im afraid i didnt understand very well. Is it mandatory to use IDs for the elements with those codes? because the reason i want to convert my code from "get element by id" into "get element by object" is right because i cant use IDs. Please dont ask me why, because the explanation would get very long. The thing is that all this is PHP generated, so the code i posted is just an excerpt, since it will take forever to post it all. I just need to know if its possible to replace the IDs by the classes.
Is it mandatory to use IDs for the elements with those codes
...............
I just need to know if its possible to replace the IDs by the classes.
With the info that has been provided it it obvious that using classes to replace ID's cannot be done as you do not have any classes to start with...
So the answer would be NO...
if by any chance I am wrong again and you want to replace all the ID.s in the code to classes then yes you can BUT you need to clearer with you explanation because your last request is a bit hazy still...
Last edited by grumpyOleMan; 02-21-2013 at 07:04 AM.
and the class exp-banner should change into ret-banner on mouse over. I just want to modify the original work from having id="exp-banner" to class="exp-banner" so i can work with classes instead of IDs.
Bookmarks