applying the same .click event to two different divs

前端 未结 6 1465
孤独总比滥情好
孤独总比滥情好 2021-02-09 07:19

i have two different divs (code was simplified, this is not the actual code.)

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-09 08:01

    You can try this syntax to do so,

    When working with Classes

    $(".className1, .className2, .classNameN").on('click', function(){
        Do_Some_Work();
    });
    

    When working with Id's

    $("#ID1, #ID2, #IDN").on('click', function(){
        Do_Some_Work();
    });
    

    When working with Combination of ID and Class

    z
    w
    x
    y
    $('#z.w , #z.y').on('click', function(){ Do_Some_Work(); //Pointer come here only when it click on `W` and `Y` });

提交回复
热议问题