var target = '<p><img alt=\"\" src=\"upfiles\/54591303758197437.jpg\" \/><\/p>'
$(function(){
var x=$('<div/>').text(target).html();
alert(x);
document.write(x)
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p><img alt="" src="upfiles/54591303758197437.jpg" /></p
Where is the last >
?
Why <p><img alt="" src="upfiles/54591303758197437.jpg" /></p>
won't show up in the webpage?
I had the same symptom on Chrome 69 (Windows).
Managed to fix it by adding a document.close()
call, as recommended by MDN:
target = '<p><img alt=\"\" src=\"upfiles\/54591303758197437.jpg\" \/><\/p>'
$(function(){
x=$('<div/>').text(target).html();
alert(x);
document.write(x);
document.close();
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>