Guest User

Untitled

a guest
Feb 6th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('<iframe width="854" height="480" src="http://www.youtube.com/embed/gYKqrjq5IjU?feature=oembed" frameborder="0" allowfullscreen></iframe>').html();
  2.    
  3. var $html = $('<iframe width="854" height="480" src="http://www.youtube.com/embed/gYKqrjq5IjU?feature=oembed" frameborder="0" allowfullscreen></iframe>');    
  4. var str = $html.prop('outerHTML');
  5. console.log(str);
  6.    
  7. $('<some element/>')[0].outerHTML;
  8.    
  9. $('<div><iframe width="854" height="480" src="http://www.youtube.com/embed/gYKqrjq5IjU?feature=oembed" frameborder="0" allowfullscreen></iframe></div>').html();
  10.    
  11. //set string and append it as object
  12. var myHtmlString = '<iframe id="myFrame" width="854" height="480" src="http://www.youtube.com/embed/gYKqrjq5IjU?feature=oembed" frameborder="0" allowfullscreen></iframe>';
  13. $('body').append(myHtmlString);
  14.  
  15. //as you noticed you can't just get it back
  16. var myHtmlStringBack = $('#myFrame').html();
  17. alert(myHtmlStringBack); // will be empty (a bug in jquery?) but...
  18.  
  19. //since an id was added to your iframe so you can retrieve its attributes back...
  20. var width = $('#myFrame').attr('width');
  21. var height = $('#myFrame').attr('height');
  22. var src = $('#myFrame').attr('src');
  23. var myReconstructedString = '<iframe id="myFrame" width="'+ width +'" height="'+ height +'" src="'+ src+'" frameborder="0" allowfullscreen></iframe>';
  24. alert(myReconstructedString);
Add Comment
Please, Sign In to add comment