Reputation: 1918
I want to add a class on the body
tag/div and on the anchor tag when I click an anchor tag.
<div id="body">
<!-- background image here -->
</div>
<ul>
<li><a href="#">First Option</a></li>
<li><a href="#">Second Option</a></li>
<li><a href="#">Third Option</a></li>
</ul>
Upvotes: 0
Views: 219
Reputation: 11751
here it is, ad class to body and anchor itself http://jsfiddle.net/testtracker/4nFUd/2/
$('ul li a').click(function(){
$('#body').addClass('classname-tobody');
$(this).addClass('classname-toanchor');
});
Upvotes: 0
Reputation: 5443
Add an event listener to the click and modify as needed...
<script>
$('ul').on('click','a',function(){
$('#body').css('background',$(this).attr('rel'));
$(this).addClass($(this).attr('rel'));
});
</script>
<div id="body">
<!-- background image here -->
</div>
<ul>
<li><a href="#" rel="blue">First Option</a></li>
<li><a href="#" rel="green">Second Option</a></li>
<li><a href="#" rel="yellow">Third Option</a></li>
</ul>
Upvotes: 2
Reputation: 5681
That should do the trick.
$("li a").click(function(){
$(this).addClass("class1");
$("#body").addClass("class2");
});
Upvotes: 0