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 } <
this is very similar to all of the answers, but why not use the ! operator twice so you can get a boolean:
!
jQuery.fn.exists = function(){return !!this.length}; if ($(selector).exists()) { // the element exists, now what?... }