Reputation: 1
I slide down and display a hidden div on click.
<style>
hide { display: hidden;}
content { background-color: black; }
</style>
<div class="content, hide">
<script>
$(.content).slideDown();<br>
$(.content).removeClass("hidden");
</script>
everything works except setting the background color. I have tried setting the background color with jQuery .css()
but it doesn't work. When I remove the hide
class it works.
Upvotes: 0
Views: 3749
Reputation: 584
<div id="scroll_Div" class="content hide">
.hide { display: hidden; }
.content { background-color: black; }
<script>
$(document).click(function(){
$("#scroll_Div").removeClass("hidden");
});
Upvotes: 0
Reputation: 7301
So a few points:
<div class="content hide">...</div>
CSS classes should start with a full stop/period (.)
.hide { display: hidden; }
.content { background-color: black; }
display: hidden
is in correct, you are after display:none
in your hide class. Alternatively you are looking for visibility:hidden
.
$('.content')
$('.content').removeClass("hide");
.hide
class as slideDown()
will add a display:block
override.<br>
which will cause a syntax error.$(function () {
$('.content').slideDown();
});
.hide { display: none; }
.content {
background-color: black;
height: 100px;
}
.content h1 { color: white; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="content hide">
<h1>My Content</h1>
</div>
Upvotes: 1
Reputation: 1870
update your code: "remove , from the html class, and add . to the classes in css, and add '' to the jquery"
HTML
<div class="content hide">
CSS
.hide { display: hidden; }
.content { background-color: black; }
Script
$('.content').slideDown();
$('.content').removeClass("hide");
Upvotes: 0
Reputation: 1064
Hi please check with the below code
<style>
.hide { display: none; }
.content { background-color: black; }
</style>
<div class="content hide">
<p>sdaaaaaaaaaaaaaaaaa</p>
</div>
<input type="button" id="clickme" value="clickme">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script>
$("#clickme").click(function() {
$(".content").slideDown();
$(".content").removeClass("hide");
});
</script>
Upvotes: 0
Reputation: 2654
Remove the comma
from class
property of div
<div class="content, hide" to <div class="content hide"
Make css like this:
.hide { display: hidden; }
.content { background-color: black; }
Make jquery like this:
$('.content').slideDown();
$('.content').removeClass("hide");
Upvotes: 0