Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery addClass does not apply style dynamically

I'm trying to apply a style dynamically to a few dropdown lists in my page. Using jQuery addClass does indeed add the class to all 'Select' elements, as i can see this from my Chrome console. However the styles are not applied to the elements.

Now if i manually add the class to each select element individually, and then save the page and refresh it, the style is applied to the element.

Any idea why the styling is not applied with jquery class injection?

$("select").addClass("select js-select");
like image 772
Tony H. Avatar asked Oct 08 '22 02:10

Tony H.


1 Answers

You said that the styles are not applied, but are the classes "select js-select" added to the select inputs? Then there must be some problem with the css or maybe the browser.

$("select").addClass(..) should work, it isn't required that you specify by ID or class.

like image 129
LazyTarget Avatar answered Oct 18 '22 11:10

LazyTarget