How to verify an element exists in the DOM using jQuery?

jquery

Solution

The get method returns the matched DOM elements:

if($("#lblUpdateStatus").get(0)){
    $("#lblUpdateStatus").click(function () { ... });
}

but I am not sure if it is a fast method.

Problem

Typically in JavaScript I do something like the below to verify an element does exist: ``` if (document.getElementById('lblUpdateStatus')) { $("#lblUpdateStatus").text(""); } ``` But, using jQuery - how can I do the same type of thing?

Original source

Related problems