JQuery addClass does not apply style dynamically

I am trying to apply the style dynamically to several drop-down lists on my page. Using jQuery addClass really adds a class to all the Select elements, as I can see it on my Chrome console. However, styles do not apply to elements.

Now, if I manually add a class to each selection item separately, and then save the page and refresh it, the style applies to the item.

Any idea why the style doesn't apply when injecting a jquery class?

$("select").addClass("select js-select");
+5
source share
4 answers

, , "select js-select" ? - css , , .

$( "select" ). addClass (..) , ID .

+2

:

<p><a href="#" id="clicker">Add Class</a></p>
<div id="select">Hello World</div>

Javascript

$("#clicker").click(function () {

    $("#select").addClass("select js-select");
});

, $( "select" ) , . , . .

, , .

+2

, onDomReady onLoad. http://jsfiddle.net/gc3wQ/9/

0

, , CSS, .

, ( div)

$(function (argument) {

  function loaded(){
    $('.landing .scroll').addClass('hidden');
  }

  loaded();

})
.hidden{
  display: none;
  transition: all ease-in-out 0.3s;
}

.shown{
  display: block;
  transition: all ease-in-out 0.3s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="shown">
 <h1>Hello</h1>
</div>
Hide result
0

All Articles