Greg Gum Greg Gum - 1 year ago 61
Javascript Question

If jquery does not find a match, is an error thrown?

Will an error be thrown if jquery does not find any items of class box-typical-body?


If so, then as far as I can tell, the correct code would be:

if ( $( ".box-typical-body" ).length ) {

I have tested, and it appears to be so, but am a novice at jquery and want to make sure.

Answer Source

$('.box-typical-body') will always return an object, its just an empty one, so the error throwing will actually depend on if the plugin jScrollPane check if the object is empty of not.

So its safer to do it your way to account for all possibilities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download