Home > front end >  Fire click event once per (different) class
Fire click event once per (different) class

Time:10-01

I'm trying to have a click event fire on any tag with the same class only once.

I tried using '.one', although, it removes itself after the first class tag is clicked.

$(document).ready(function() {   
    $(".dropdown").one('click', function() { 
        ...
    });
});

The code is bought in from another .php file on the same directory with some server information so there are multiple (no end) in the number of tags with the same class.

<div class = \"dropdown\" id=" . $row["name"] . "dropdown" . ">
                    <div>". $row["email"] . "</div>
                    <div>name:" . $row["name"] ."</div>
                    <div>". $row["email"] ."</div></div>
                    ";

Any recommendations?

CodePudding user response:

As per your comments what you actually needs to do is apply a check of text available already or not?

$(document).ready(function() {   
    $(".dropdown").on('click', function() { 
       if(empty($('<text wrapper class or id>').text())){
           // add code to bring the info
       }
       //rest other code.
    });
});

Note : I fyou can show your code HTML then I can Update my code to give you concreete answer. The above will guide you how to proceed.

  • Related