Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is jquery .bind() deprecated?

Tags:

jquery

bind

Is jquery bind() deprecated or it can be used safely?

I see a lot of comments about bind() being deprecated in comments and answers across SO like: Jquery Event : Detect changes to the html/text of a div

Is there a JavaScript/jQuery DOM change listener?

and don't know if it is safe to use it or not (regardless of it being better or worse).

There is nothing about it being deprecated here: https://api.jquery.com/bind/

like image 972
Claudiu Creanga Avatar asked Nov 11 '15 16:11

Claudiu Creanga


2 Answers

I don't believe its deprecated but on is the preferred method of attaching events.

http://api.jquery.com/bind/

Deprecated means they will be removing it in the future but their docs don't seem to say that.

EDIT:

As of jQuery 3.0 bind IS deprecated. The above link is still relevant but has since been updated. From their docs:

As of jQuery 3.0, .bind() has been deprecated. It was superseded by the .on() method for attaching event handlers to a document since jQuery 1.7, so its use was already discouraged.

like image 156
AtheistP3ace Avatar answered Sep 21 '22 19:09

AtheistP3ace


No it's not, that are a difference between .on and .bind basically .bind is only called directly from a element i.e. $("#elem").bind(...), so the element must exist by the time the bind function is called. And .on can be "bind" on document i. e. $(document).on("click",".class",funcion(){...});, so if you add an element dynamically by using .append or other way, the event will be valid.

like image 45
Marcus Abrahão Avatar answered Sep 22 '22 19:09

Marcus Abrahão