oimoim oimoim - 23 days ago 5x
HTML Question

JavaScript getting complete code of element when mouseover or onclick

How can I get the complete HTML code of the element I'm mouseovering or clicking?

document.onmouseover = function(e){
can I get the full underlying HTML code of the element which triggered the event?

Right now, I am able to get the tag name or id or whatever.
What I would like is the whole code.

For example; if I'm mouseovering a table, I would like to get the string:

Is this possible?


IE already has element.outerHTML

and this for others:

if (!('outerHTML' in document.documentElement)) {
    function getOuterHTML(element){
        var dummy = document.createElement('html');
        var result = dummy.innerHTML;
        dummy.innerHTML = '';
        return result;
    function getOuterHTML(element){
        return element.outerHTML;

you can use it like this:

 alert( getOuterHTML( document.getElementById("elementID") ) );