javascript - replace all images with inputs elements jquery -
javascript - replace all images with inputs elements jquery -
i need find images textarea value , replaces inputs text elements , value of src of img reemplace
after final string output on new div ('#newdiv')
my script dont replace nil dont know why
here have done far,
<html> <head></head> <body> <textarea id="caja"></textarea> <input type="button" onclick="parsinghtml()" value="read"> <div id="newdiv"></div> <script type="text/javascript" src="jquery-1.11.1.min.js"></script> function parsinghtml() { var content = $('#caja').val(); var newcontent = $(content).find("img").replacewith('<input type="text">'); alert(newcontent) $('#newdiv').html(newcontent); }; </body> </html>
any ideas? in advance!
there 2 problems can see
newcontent
referring img
elements, not finish content since passing value jquery
, if value not start <
considered selector not element creation command so
class="snippet-code-js lang-js prettyprint-override">//dom ready handler jquery(function($) { //click event handler registration $('#read').click(parsinghtml); }) function parsinghtml() { var content = $('#caja').val(); var newcontent = $('<div />', { html: content }); newcontent.find("img").replacewith('<input type="text">'); console.log(newcontent) $('#newdiv').html(newcontent.contents()); };
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <textarea id="caja"></textarea> <input type="button" id="read" value="read"> <div id="newdiv"></div>
javascript jquery html
Comments
Post a Comment