Can you please take a look at this demo and let me know why the change()
function is not able to slideDown()
a hidden
element in Bootstrap 3?
Here is the code I have
$(function() {
$('input:radio').change(function() {
if($(this).val()== 'Dog') {
$('#hidden-list-1').slideDown();
}
if($(this).val()== 'Bird'){
$('#hidden-list-2').slideDown();
}
});
});
Can you please take a look at this demo and let me know why the change()
function is not able to slideDown()
a hidden
element in Bootstrap 3?
Here is the code I have
$(function() {
$('input:radio').change(function() {
if($(this).val()== 'Dog') {
$('#hidden-list-1').slideDown();
}
if($(this).val()== 'Bird'){
$('#hidden-list-2').slideDown();
}
});
});
Share
Improve this question
edited Jul 5, 2015 at 19:12
Jon Rubins
4,4139 gold badges35 silver badges52 bronze badges
asked Jul 5, 2015 at 18:31
SuffiiSuffii
5,78415 gold badges61 silver badges94 bronze badges
5 Answers
Reset to default 14As the other answers have already mentioned the issue is boostrap has a style like this
.hidden{
display: none !important;
}
One way to solve this is by removing hidden class.
$('#hidden-list-1').hide().removeClass('hidden').slideDown();
Here is a demo https://jsfiddle/dhirajbodicherla/zzdL5jp7/3/
It seems to be an issue of the important tag in CSS. From the Bootstrap documentation (http://getbootstrap./css/), the show and hidden classes are marked with important:
.show {
display: block !important;
}
.hidden {
display: none !important;
}
The css changes applied by jQuery slideDown() are most likely getting ignored. If you take this out and replace with a style="display:none;"
without the important, the slideDown() will work. I added that to the fiddle: https://jsfiddle/zzdL5jp7/1/
This is because the hidden class forces an element to always be hidden. I'm pretty sure it does something like:
display: none !important;
So you have to modify your code to remove that class after sliding the element down. Or use your own CSS to hide the element (so you don't have !important
there.
If you modify your JSFiddle to have the CSS:
#hidden-list-1 {
display: none;
}
And remove the hidden
class, you'll see that it works as expected.
The hidden
class you've added to #hidden-list-1
and #hidden-list-2
is overriding the display property change done by your JS. Removing the hidden
class and declaring both elements hidden in CSS will solve your problem.
update your css code
.show {
display: block !important;
}
.hidden {
display: none !important;
}