javascriptdom

How to check if object is a DOM element?


I have a function:

function Check(o)
{
    alert(/* o is a DOM element ? "true" : "false" */);
}

How can I check if the parameter o is a DOM element or not?


Solution

  • A DOM element implements the Element interface. So you can use:

    function Check(o) {
        alert(o instanceof Element);
    }