开发者

Multiple Functions on a Single Event with JQuery/Javascript

开发者 https://www.devze.com 2023-02-10 03:01 出处:网络
What is the best way to call two functions upon a single click event? There will be multiple elements req开发者_如何学运维uiring this script, so the script must act only upon the element being clicke

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

There will be multiple elements req开发者_如何学运维uiring this script, so the script must act only upon the element being clicked — not all the elements at once.

Let me know if I need to provide more details. Thanks again for all your help.


$(function() {
    $('a').click(function() {
        func1();
        func2();
    });
});


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

精彩评论

暂无评论...
验证码 换一张
取 消