Wonder if there's any way to check if elements with the same class exists in a document.
For example:
<div class="panel">panel 1</div>
<div class="panel">panel 2</div>
<div class="panel">panel 3</div>
JS:
if ( $('.panel')[0] ) {
console.log('exists')
}
.. but I want to check if MORE THAN ONE panel
element exists, alteast 2.
Try to use the length
property to accomplish your task,
if($('.panel').length > 1) {
console.log('yes, more than one element exist')
}
if ( $('.panel').length >= 2 ) {
console.log('exists')
}
This should work
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