javascript - Different results when using jQuery.filter and jQuery.find on Ajax xhr response -
i have ajax menu on section of site. menu sends request retrieve page content of clicked link. content request full html page elements found on page including script , style tags. use jquery.filter on xhr response script html script tag. when try style sheet link tag not working. gives me style link tags if use jquery.findon xhr. ajax use
$.ajax({ type: 'get', url: url, datatype: "html", async: false, error: function(oxhr, type, exception) { console.dir(exception); }, success: function(xhr) { var scripts = $(xhr).filter('.vod'), styles = $(xhr).find('link[name="vod"]'); $(styles).each(function() { if (this && this.href) { loadstyle(this); } }); $(scripts).each(function() { if (this.text) { $.globaleval(this.text || this.textcontent || this.innerhtml || ''); } else if (this.src || this.href) { loadscript(this); } }); $('#container').html($(xhr).find('#content')[0]); } });
jquery strips html, head, , body tags response. because of how javascript works when set innerhtml of t adiv element. not have full html page, have child nodes of body , head tags.
so need use filter because link elements not child element.
what expecting : [htmlnodereference]
what [title, link, h1, div, etc]
Comments
Post a Comment