javascript - jquery - issue getting script tags after two .filter()'s -
i have ajax response want parse tags, , want find script tags within specific div id. below capture , run each javascript within page:
success: function(data) { var dom = $(data); dom.filter('script').each(function(){ var obj = $(this); $('#my_div').append(obj); }); },
when try filter first div id, , script not append anything. have access reponse html obviously, , can see there should multiple tags in 'js_outer_div' div:
var dom = $(data); dom.filter('js_outer_div').filter('script').each(function(){ var obj = $(this); $('#my_div').append(obj); });
unfortunately have no control on response html. there way filter first div , script wanting?
edit: sample html response:
... <div id="i9-content-div"> <script xmlns:efactions="http://www.enginframe.com/2009/efactions" xmlns:grid="http://www.enginframe.com/2000/grid" type="text/javascript"> ... </script> <script type="text/javascript"> ... </script> </div>
i can see there should multiple tags in 'js_outer_div' div
if js_outer_div
class name filter
method should be:
dom.filter('.js_outer_div')...
but no, doesn't solve problem. filter
method filters top level elements in collection. jquery collection not flat, preserves element hierarchy. should use find
method. find
method selects descendants of wrapper element in collection, can generate div
element , use html
method setting it's content using data
variable. find
method works whether target div.js_outer_div
top level element or not.
$('<div/>').html(data).find('.js_outer_div script').each(...)
Comments
Post a Comment