Toggling css style change with Jquery
I am creating am able to change the color of a link once it has been clicked. I would like to take it one step further and toggle it back to the previous color once another link in the set is clicked. How address the link with 'this' to do the initial change how do I address it when switching it bac开发者_JS百科k?
This is what I am doing currently.
$(this).css("color","yellow");
Thanks
Have all your links selectable as a group, either with a common place in your html structure, or by giving each link the same class, etc. Assuming you've given each link that you want to behave this way the class "linkGroup". Run this script:
$(document).ready(function() {
$(".linkGroup").onclick(function(){
$(".linkGroup").css("color","blue");
$(this).css("color","yellow");
});
});
If you're new to JQuery, the "document ready" function is just a great way to have script run on startup, but to wait until the document is ready and has everything loaded.
The simplest way would be to set all the links back to whatever color you want and then set the color of this
:
$('#linkset a').css("color","black");
$(this).css("color","yellow");
Assign all the links in your group to a class, and then do $('.myclass').css('color','white');
User this $('#lnk').toggleClass('bounce')
imran
精彩评论