Problem with jquery "live" function

problem

this works great:

$('#edit_curriculum .generated').children().blur(function(){ console.log(this); }); 

but this is not so:

 $('#edit_curriculum .generated').children().live('blur', function(){ console.log(this); }); 

obs: functions wrapped in the $(document).ready event.


exits

working:

 <input type=​"text" name=​"phones[]​" class=​"medium phone valid"> 

does not work:

 Uncaught Syntax error, unrecognized expression: ) k.errorjquery.js:17 k.filterjquery.js:17 kjquery.js:17 c.querySelectorAll.kjquery.js:17 k.matchesSelectorjquery.js:17 f.extend.filterjquery.js:17 f.fn.extend.isjquery.js:17 f.fn.extend.closestjquery.js:17 Njquery.js:16 f.event.handlejquery.js:17 f.event.add.kihandle.kjquery.js:16 f.event.triggerjquery.js:17 ejquery.js:17 
+6
source share
1 answer

From jQuery live () documentation:

Attach a handler to the event for all elements that match the current selector , now and in the future.

This function is designed to work with selector , not with a set of elements. I would use the following syntax:

  $('#edit_curriculum .generated > *').live('blur', function(){ console.log(this); }); 

This selector will receive any coming children (therefore, what you had before), but with selection , not traversal . This should allow you to use live() , as you would expect. Hope this helps!

+7
source

Source: https://habr.com/ru/post/895033/


All Articles