I have this code.
CSS
body {
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
}
.slidingDiv {
height:300px;
background-color: #99CCFF;
padding:20px;
margin-top:10px;
border-bottom:5px solid #3399FF;
}
.show_hide {
display:none;
}
HTML
<a href="#" class="show_hide">Show/hide</a>
<br />
<div class="slidingDiv">
Fill this space with really interesting content.
<a href="#" class="show_hide">hide</a>
</div>
JS
$(document).ready(function(){
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function(){
$(".slidingDiv").slideToggle();
});
});
Someone tell me if its possible to add in this jquery function that if i click on it, at the same time to show/hide a new div, change a class to an tag and remove another class from another tag? How can i do it?
Thanks.
I have this code.
CSS
body {
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
}
.slidingDiv {
height:300px;
background-color: #99CCFF;
padding:20px;
margin-top:10px;
border-bottom:5px solid #3399FF;
}
.show_hide {
display:none;
}
HTML
<a href="#" class="show_hide">Show/hide</a>
<br />
<div class="slidingDiv">
Fill this space with really interesting content.
<a href="#" class="show_hide">hide</a>
</div>
JS
$(document).ready(function(){
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function(){
$(".slidingDiv").slideToggle();
});
});
Someone tell me if its possible to add in this jquery function that if i click on it, at the same time to show/hide a new div, change a class to an tag and remove another class from another tag? How can i do it?
Thanks.
Share Improve this question edited May 18, 2012 at 23:32 timrwood 10.7k5 gold badges38 silver badges42 bronze badges asked May 18, 2012 at 18:42 bombaibombai 9672 gold badges18 silver badges27 bronze badges 1- Are the tags related in any way hierarchically? If so, yes. If not, no. – Tejs Commented May 18, 2012 at 18:44
4 Answers
Reset to default 6yes you can, take a look of the method addClass and also of the removeClass.
remove: jQuery('element').removeClass('class');
reference
add: jQuery('element').addClass('class');
reference
And you can use toggleClass to switch.
toggle: jQuery('element').toggleClass('class otherClass');
reference
Add class:
$('selector').addClass('className');
Remove class:
$('selector').removeClass('className');
yes of course you can add or remove classes
<script type="text/javascript">
$("#ButtonId").click(function () {
$('#itemid').removeClass('classname');
$('#itemid').addClass('classname');
});
</script>