How can I check the existence of an element in jQuery?
The current code that I have is this:
if ($(selector).length > 0) { // Do something } <
How about:
function exists(selector) { return $(selector).length; } if (exists(selector)) { // do something }
It's very minimal and saves you having to enclose the selector with $() every time.
$()