jquery Add and Remove Classes?
Posted
by Steven
on Stack Overflow
See other posts from Stack Overflow
or by Steven
Published on 2010-06-18T02:18:56Z
Indexed on
2010/06/18
2:23 UTC
Read the original article
Hit count: 330
jQuery
Hello,
I need a script that adds a 2 to the end of a class in a div with the id .sideboxtopleft on clicking of a link with the id of posts.
<script>
$(".posts").click(function () {
if ($('.sideboxtopleft').is('#sideboxtopleft2')) {
$('.sideboxtopleft').removeClass('2');
}
else{
$('.sideboxtopleft').addClass('2');
}
});
</script>
<div id="sideboxtopleft" class="sideboxtopleft">
<a href="#post" id="posts"><h3>RECENT POSTS <div id="arrow" class="arrow"></div></h3></a>
</div>
<div id="sideboxtopright" class="sideboxtopright">
<a href="#comments" id="comments"><h3>RECENT COMMENTS <div id="arrow" class="arrow2"></div></h3></a>
</div>
However it doesn't seem to want to work properly. Any help?
© Stack Overflow or respective owner