Selecting Elements | jQuery Learning Center


Sat May 29 2021 01:01:00 GMT+0000 (UTC)

Saved by @ejiwen

// Testing whether a selection contains elements.
if ( $( "" ).length ) {

The best way to determine if there are any elements is to test the selection's .length property, which tells you how many elements were selected. If the answer is 0, the .length property will evaluate to false when used as a boolean value.