Showing posts with label jquery Assigning more than one class for one event. Show all posts
Showing posts with label jquery Assigning more than one class for one event. Show all posts

Thursday, February 8, 2018

jquery using same event for multiple classes

You can attach same event for multiple css classes as displayed below.

<script type='''text/javascript">

function OnClicked(){
    if ($(this).hasClass('tag1')){
        // code
    }
    else {
         // code
    }
}

  $(function() {
    //method 1
     $(".tag1, .tag2").click(OnClicked);

         //method 2
        $(".tag1, .tag2").click(function(){
            alert("clicked");   
        });​








});

</scrip>

Regards,
Samitha