Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print entire HTML element in JavaScript?

Tags:

javascript

I want to print the entire element including tag name, attribute name/value pairs and innerHTML. How can I do it in JavaScript (jQuery)?

for example:

var elArr = document.getElementsByTagName('link');
alert(elArr[0].printEntireElement());

//expected output might be 
<link href="/css/common.css" rel="stylesheet" type="text/css">`

Note that for link element outerHTML is not defined!

like image 600
celicni Avatar asked Apr 13 '10 15:04

celicni


People also ask

How do I print an entire HTML page?

Open the web page. 2. Press Ctrl + A 3. Right click on the page and left click on “Print” 4.

How do you print screen in JavaScript?

Window print() Method The print() method prints the contents of the current window. The print() method opens the Print Dialog Box, which lets the user to select preferred printing options.


1 Answers

Use an outerHTML jQuery plugin, like this one, or this one.

like image 167
Ben S Avatar answered Sep 23 '22 00:09

Ben S