Multiple Functions on a Single Event with JQuery/Javascript

前端 未结 2 581
醉梦人生
醉梦人生 2021-02-14 15:26

What is the best way to call two functions upon a single click event?

There will be multiple elements requiring this script, so the script must act only upon the element

2条回答
  •  野性不改
    2021-02-14 16:04

    jQuery will handle that for you quite nicely, see example:

    $('div').click(function(){
        alert($(this).text()+' clicked');
    })
    .click(function(){
        $(this).css({'color':'#ff0000'});
    });
    Button 1
    Button 2

    Here's a jsFiddle example: http://www.jsfiddle.net/pcASq/

提交回复
热议问题