javascript - Adding a class to images of a dynamically loaded content -
i loading content dynamically. content in html form , need of it's images , add together class them. have done:
var jsonobj = json.parse(http_request.responsetext); console.log($(jsonobj.content).find("img").addclass("img-responsive")); document.getelementbyid("mymodalcontent").innerhtml = jsonobj.content; the console shows me class has been added dom doesn't have class. why happening?
your code creating new object, add together classes , then, alter innerhtml old string. should alter new object html :
var jsonobj = json.parse(http_request.responsetext); var $el = $(jsonobj.content).find("img").addclass("img-responsive").end(); document.getelementbyid("mymodalcontent").innerhtml = $el.prop('outerhtml'); or improve :
var jsonobj = json.parse(http_request.responsetext); var $el = $(jsonobj.content).find("img").addclass("img-responsive").end(); $("#mymodalcontent").append($el); javascript jquery html css ajax
No comments:
Post a Comment