Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jquery in comparing the two selectors?

Tags:

jquery

I have to compare two selectors and I was wondering why does this return false in firebug...and how do I compare two selectors

$('.product-info:last') == $('.product-info:last')

this is what I have to do

    var previous = $('.product-info:visible');
    if(previous == $('.product-info:last')){
        return false;
    }
like image 209
Matt Elhotiby Avatar asked Nov 14 '11 21:11

Matt Elhotiby


2 Answers

The reason $('.product-info:last') !== $('.product-info:last') is because jQuery create a new object for each one of those, they are not the same jQuery object.

Use is instead to check if elements are the same.

previous.is('.product-info:last') 
like image 133
aziz punjani Avatar answered Oct 05 '22 08:10

aziz punjani


try :

$('.product-info:last').get(0) == $('.product-info:last').get(0)
like image 45
Royi Namir Avatar answered Oct 05 '22 10:10

Royi Namir