I’m using jQuery in my web application. I’ve been using .bind() but I see that it is a little slow, so while reading the documentation I read about .on() and .delegate(). I understand how .delegate() works but I’m not clear on what is the difference between it and .on() or which is better in which scenarios.
Also I’m using jQuery 1.6 so I would like to know if it is worth it to prepare my script for jQuery 1.7 by putting in a condition similar to the following:
if(typeof $(selector).on == 'function'){
/* use .on() */
}else{
/* use .delegate() */
}
Is this a good idea (to prepare for .on()) or is it just looking for trouble for nothing?
Please help me to get clear understanding of these methods.
The
.on()syntax is the new syntax that version 1.7 uses and it is meant to substitute.bind(),.delegate()and.live().More here -> http://blog.jquery.com/2011/11/03/jquery-1-7-released/