...........">

How to get innerHtml body without iframe with jquery

I have a html page something like this

<body><iframe ></iframe><div id="menu">......</div>.....</body> 

I want to get innerHTML body, but without iframe? How can i do this in jquery?

+4
source share
3 answers

Try .clone :

 $(document.body) .clone() .find('iframe') .remove() .end() .html(); 
+4
source
 $(document).ready(function(){ $('body').not('iframe').html(); }); 

which should get everything in the body, but iframe. you probably want to store this in a variable or something for reference later

0
source

I found another way to do this

 var page = $('body').html(); page = $('<div>' + page + '</div>'); var html = $(page).find('iframe').remove().end().html(); 

The html variable contains html without an iframe.

And it works with IE since jquery.clone () does not work on my page, maybe due to incorrect html like @lonesomeday suggested

0
source

Source: https://habr.com/ru/post/1336027/


All Articles