Is jquery .bind() deprecated?

前端 未结 4 1606
长情又很酷
长情又很酷 2021-01-17 23:11

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: Jque

4条回答
  •  花落未央
    2021-01-17 23:47

    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.

提交回复
热议问题