Is there a simple way to change the id of a div by clicking on a link?
Here is what I am going for:
Link1 gives div id=1
Link2 gives div id=2
Link3 gives div id=3
I am trying to make both an image and text change by clicking on the appropriate link.
I figured I could change the id of div with the image and use a sprite to get the right part of the image to show up
I would also like the text in the second div to change
Maybe one questions that still covering me is, why do they still use the $('div').removeClass('geek').addClass('superman') if they just have one classname, while we can use a simpler way: $('div').attr('class', 'superman')
No idea Hompimpa – I just checked and attr() removes the previous class anyway – my initial thought was maybe it added the class and you still had to remove one. But obviously not. I think removeClass and addClass are more for when you have multipul classes and actually support function expansion better then than the attr() funtion (as you might add a class later that you don’t want removing…).
@Robskiwarrior: Yeah, that’s why I said if we only have one class. And moreover, (I never tried to explore the JQuery deeper. It is very confusing) I think .addClass(), .removeClass() and .toggleClass() are derived from the .attr() function.
Thank you :)
In your example, it is when you click the text that the links get the new class and change color.
I will try to work with it so that when you click the links the text changes color ie gets the right class according to the link that was clicked.
Thank you for sharing the code with me and all your help.