Reputation: 111
I have a small problem with my jQuery script.
<script language="javascript">
$(document).ready(function(){
$('.roll-li').click(function(){
if ($('.hideshow').is(":hidden")) {
$('.hideshow').slideDown("slow");
}
else {
$('.hideshow').slideUp("slow");
}
});
});
</script>
How to modify script, so div that div with class "hideshow" that I'm slideing up and down, will be hidden on default?
Upvotes: 1
Views: 570
Reputation: 21630
In css,
.hideshow { display: none; }
In jquery (no need for checking visibility, just use slideToggle()
$(".roll-li").click(function() {
$(".hideshow").slideToggle("slow");
return false;
});
(also consider changing your html to use ids instead of classes, as finding these via jquery is more efficient)
Upvotes: 1
Reputation: 1217
<script language="javascript">
$(document).ready(function(){
$('.hideshow').hide();
$('.roll-li').click(function(){
if ($('.hideshow').is(":hidden")) {
$('.hideshow').slideDown("slow");
}
else {
$('.hideshow').slideUp("slow");
}
});
});
</script>
Just add the line:
$('.hideshow').hide();
That's if I understood your question properly.
Upvotes: 2
Reputation: 124325
You don't really need to do that in the script. You just put style="display: none"
on the div, or add display: none
to the CSS for .hideshow
.
Upvotes: 5