tags:

views:

54

answers:

2

Is it possible in jQuery to add an element's event? For example if I wanted to add a .fadeIn() to an element when it is clicked but also retain any other functionality that may already exist (given that I do not know if there is or isn't currently anything firing on click).

+6  A: 

jQuery doesn't overwrite events, it adds to them. So if you did:

$(document).ready(function() {
    $("#test").click(function () { $(this).append("test<br />"); });
    $("#test").click(function () { $(this).append("test 2<br />"); });
});

with a div looking like:

<div id="test">click me <br /></div>

When you click on the div, it will append "test" and "test 2" at the same time.

Brandon Montgomery
A: 

From what I understand, you want to have multiple events mapped to the same element right?

Yes, it is possible. The order it will run might be a bit unpredictable, but you can have them.

fmsf