Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addEventListener in jQuery [duplicate]

Possible Duplicate:
jQuery equivalent of JavaScript's addEventListener method

Also from a very good jQuery tutorial on : http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8

What is the jQuery equivalent for the following statement;

element1.addEventListener('click',doSomething2,false)

If it is the bind() method, is there any option to specify the last parameter (i.e. event bubbling or capturing ... true/false)

like image 778
Diana Avatar asked Aug 11 '11 11:08

Diana


2 Answers

Try this

// Setting the third argument to false will attach a function
// that prevents the default action from occurring and 
// stops the event from bubbling.
$("#element1").bind("click", doSomething2, false);
like image 154
ShankarSangoli Avatar answered Nov 18 '22 21:11

ShankarSangoli


Yes I'm pretty certain .bind() will work as you need it. Check out the jQuery .bind() docs page I'm sure you can figure out the setup. Demo code below:

$(document).ready(function() {
    $("#element1").bind('click', function() {
        // do something on click
    } 
});
like image 34
Jake Avatar answered Nov 18 '22 21:11

Jake