Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  90] [ 7]  / answers: 1 / hits: 155856  / 11 Years ago, wed, november 6, 2013, 12:00:00

I would like to convert a html element created from a string back to the string after some modifications. But I get an empty string instead.



$('<iframe width=854 height=480 src=http://www.youtube.com/embed/gYKqrjq5IjU?feature=oembed frameborder=0 allowfullscreen></iframe>').html();


How can I do that another way?


More From » jquery

 Answers
20

You can do this:





var $html = $('<iframe width=854 height=480 src=http://www.youtube.com/embed/gYKqrjq5IjU?feature=oembed frameborder=0 allowfullscreen></iframe>');    
var str = $html.prop('outerHTML');
console.log(str);

<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js></script>





FIDDLE DEMO


[#74472] Tuesday, November 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kenyamelinad

Total Points: 339
Total Questions: 85
Total Answers: 116

Location: Marshall Islands
Member since Sun, Aug 29, 2021
3 Years ago
;