Say I have the following:
$('#foo')
I'd like to know if that selector matches anything. How do I test for this?
$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.
if ($('#foo').length > 0) {
// do things
}
should do it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With