Javascript DOM elements hide class and the element not present are same?

107 views Asked by At

I am currently working on a project where most of the code has been written by someone else . I was supposed to do some slight modifications in the existing script to incorporate changes in a new file. I came across a situation where it was very confusing . The scenario is as cited below:

I have an element named as complextabs and it is being used for almost all the pages, except for the one which is being created newly. The situation is there is a code snippet that is written as $('.complextabs').hasClass('.hide'). this incredibly returns the same as when the element complextabs is not even present in the page. Can someone please throw some light on this

And yeah, I am working on Backbone.js . Has this got something to do with the use of Backbone.js

Any suggestion and advice is highly appreciated

1

There are 1 answers

3
ivarni On BEST ANSWER

Nope, that has nothing to do with the use of Backbone.

Consider the following:

$('.asdasda').hasClass('hide')

This will return false, and it should return false because $('.asdasda') does not return any results. Just running that will yield a JQuery wrapper over an empty list and since there are no elements then obviously there's nothing in there with the css class hide.

If you want to check that there is an element with both the complextabs and the hide class then use $('.complextabs.hide').length.