My favourite is to extend jQuery with this tiny convenience:
$.fn.exists = function () {
return this.length !== 0;
}
Used like:
$("#notAnElement").exists();
More explicit than using length.
More Related Contents:
- jQuery selectors with variables
- How can I get the ID of an element using jQuery?
- What is fastest children() or find() in jQuery?
- jQuery Selector: Id Ends With?
- jQuery OR Selector?
- jQuery selector value escaping
- jquery find versus context selection
- How to select last child element in jQuery?
- jQuery :contains() selector uppercase and lower case issue
- CSS selector case insensitive for attributes
- jQuery get all divs which do not have class attribute
- jQuery Set Select Index
- Difference between :hidden and :not(:visible) in jQuery
- Using jquery to get all checked checkboxes with a certain class name
- How can I get the corresponding table header (th) from a table cell (td)?
- jQuery selector for the label of a checkbox
- Select elements without any class [duplicate]
- jQuery attribute selector for multiple values
- jQuery: selector (classname with space)
- JQuery data selector not updating with .data
- :nth-of-type() in jQuery / Sizzle?
- Difference between CSS selector and jQuery filter?
- jQuery hasClass() – check for more than one class
- Changing the child element’s CSS when the parent is hovered
- addID in jQuery?
- CSS selector to select an id with a slash in the id name?
- Using jQuery how do I select a range of rows?
- How to select a table column with jQuery
- Performance of jQuery selectors vs local variables
- Can jQuery selectors be used with DOM mutation observers?