javascript - jQuery $.post returning Object length: 0 -
i'm trying make pagination script using ajax, refuses grab correct id. code here
$(document).on('click','#pagination a',function(e){ e.preventdefault(); var link = $(this).attr('href'); var $content = '.everything'; $.post(link+'', function(data){ var $new_content = $($content,data); console.log($new_content); },'html'); });
this returning following in console:
object { length: 0, prevobject: object, context: undefined, selector: ".everything" }
the object .everything
exists in dom, item appears if console.log(data);
. element contains 2000 characters.
the issue doesn't happen when try grab element less content doing console.log($('.logo',data));
when elements in html snippet, inside outermost element.
for example $('span', '<div><span></span></div>')
returns jquery object containing span
element, $('div', '<div><span></span></div>')
returns empty jquery object.
if want include outermost element in search, wrap in element:
var elements = $('<div>').append(data); var $new_content = elements.find($content); console.log($new_content);
Comments
Post a Comment