Uncaught TypeError: Cannot call method 'replace' of undefined in jquery -


i have template in javascript act html "load-more" widget. want replace variables in template dynamic data have pulled database. trying replace variable "id" in specific div dynamic data. here code:

template:

var likes_template = '<div class="activity_sub_header">you want <span class="stage_name"></span> play {{auth::user()->city}}!</div>'                +'<br>'                +'<div class="description">'                +'<div class="activity_body">description ... <a href="/artists/id">see more...</a></div>'                +'</div>'                +'<div class="image"><a href="/artists/id"><img src="image_path" alt="" height="80" width="80" class="img-rounded"></a>'                +'</div>'                +'<br><br><br>'; 

dynamic replacement:

for (like in likes){             // clone element             var $like = $(likes_template).clone();             $like.attr('id', 'like-' + likes[like].id);  var $imgid = $like.find('div.image');             $imgid.html($imgid.html().replace('id', likes[like].id));  } 

as can tell code, trying replace variable "id" in div class="image". however, when running this, getting error in title:

uncaught typeerror: cannot call method 'replace' of undefined in jquery 

i have been able replace other variables method, not one. not sure doing wrong. thank help!

div.image not descendant of selector element.

but 1 of sibling.

you need use filter

$like.find('div.image'); 

supposed

$like.filter('div.image'); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -