I need to fetch body tag from the url which i open. I am using following code but it is not working. Please suggest.
document.getElementsByTagName('body')[0].innerHTML;
Thanks Tanu
The basic tag is written like this <body> </body> , with the document's content inserted between the opening and closing tags. On any normal-sized HTML document, you'll usually see the opening tag ( <body> ) near the top of the document and the closing tag ( </body> ) near the bottom.
Finding HTML Elements by CSS Selectors If you want to find all HTML elements that match a specified CSS selector (id, class names, types, attributes, values of attributes, etc), use the querySelectorAll() method. This example returns a list of all <p> elements with class="intro" .
The <body> tag defines the document's body. The <body> element contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
The <body> HTML element represents the content of an HTML document. There can be only one <body> element in a document.
Copy below code in url navigation bar. See, whole body content alerted.
javascript:(alert(document.body.innerHTML));
Its means you can get the body content by just body.innerHTML. you don't require to use getElementsByTagName.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With