Multiple Functions on a Single Event with JQuery/Javascript

前端 未结 2 578
醉梦人生
醉梦人生 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 15:42
    $(function() {
        $('a').click(function() {
            func1();
            func2();
        });
    });
    
    0 讨论(0)
  • 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'});
    });
    <div>Button 1</div>
    <div>Button 2</div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

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

    0 讨论(0)
提交回复
热议问题