Help a newbie. There is a button on the page, it is created using a script from another service (widget to order a call). This button has lt-label and lt-online or lt-offline classes. It is created dynamically and placed in the body .

There is also a static fixed button.

Question: how can js hide a static button if dynamic has a class lt-offline ?

Tried so

 $(document).ready(function() { if (document.getElementsByClassName) { var redTags = document.getElementsByClassName('lt-label'); if (redTags.is(".lt-offline")) { $("#lb-wrapper").css({ 'display': 'none' }); }; }; }); 

But it does not work because of the fact that here and just js and jquery. How do I do right?

  • in general it would be a good example of markup - Grundy
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Jquery provides the hasClass method, which returns true if the element has the required class, false if it does not.

 var $elem = $(".someClass"); $elem.hasClass("someClass"); // true 

Well, respectively, for your case:

 $(document).ready(function() { var $redTags = $('.lt-label'); if($redTags.hasClass(".lt-offline") { $("#lb-wrapper").hide(); } } 

hide - the method that the element hides (for the place of css({display: "none"}) );

    Another option with .toggle

     $(document).ready(function() { $("#lb-wrapper").toggle($('.lt-label.lt-offline').length > 0); });