jquery - How to change src attribute of all images in anonymous function -
i'm trying html page $.get function. content of page contained in "data" object. want parse data , change src attribute of img's tag. code work. have access src's object "data" isn't updated in end.
$.get("url/to/page.html", function(data){ $("img", data).each(function() { $(this).attr("src", newsrc); }); }); so "data" html content of page.html , , want change src's "newsrc" var new url of source. if print data in end, haven't new src.
edit: solution is:
$.get(this.htmlasset.get('url_asset'), function(data) { var $data = $(data); $data.find('img').each(function(){ $(this).attr("src", newsrc); }); $('#redactor').setcode($('<div></div>').append($data).html()); thank's
you need convert html dom objects before can operate on them such.
$.get("url/to/page.html", function(data){ var $data = $( data ).find( 'img' ).each(function() { $(this).attr("src", newsrc); }); // $( 'body' ).append( $data ); or whatever want }); note should use $data there on since contains modified dom elements. data still contains original html string.
Comments
Post a Comment