Live chat Whatsapp
Live chat Whatsapp
Attiva Web - Realizzazione siti internet, ecommerce

How to check if an element exists with jquery

    • For technical needs of various kinds you happen to want to know whether or not there is an html element within a web page, whether it is a div, an ul/li, select/option does not matter, thanks to jquery è you can find out with a few lines of code. suppose you want to know whether or not there is a div with a class called article, code is the following:

      if($(".articolo").length){
        //fa qualcosa
      }

      speaking in more human terms the above code says: if the length of the item element with articolo class è greater than zero and/or is set, do something.

      The equivalent could have been:

      if($(".articolo").length > 0){
        //fa qualcosa
      }

      Until next time!

      Francesco // 29-07-2020 // jQuery

    Lascia un commento

    Invia commento


    ATTENZIONE: il tuo commento verrà prima moderato e se ritenuto idoneo sarà pubblicato