Reputation: 7306
CSS
.active
{
display: block;
}
JS
$("#li_1 ul").addClass('active');
JS
$("#li_1 ul").css('display', 'block');
Which leads to me my question, why does the css function work and not the addClass? There's no difference between the selectors at all.
Additional info -
Upvotes: 1
Views: 1086
Reputation: 85126
Without seeing your HTML it's hard to say for sure why it's not working. I can say that the JS you've posted should work fine. I have a working example here:
One thing that jumps out is that this selector $("#li_1 ul")
looks a little weird. do you really have a ul
element that is a child of an element with an id that implies it is an li
?
Your second JS example is applying style directly to the element which will overwrite any CSS Class styles that are being applied, so if you have some other CSS present that is affecting that element this could explain the behavior you are seeing.
Upvotes: 0
Reputation: 15375
What about using this statement:
.active {
display:block !important;
}
I think something overrides your .active
rule in your CSS stylesheet.
More informations about CSS priorities right here.
Upvotes: 4