JQuery Compare Selectors


/ Published in: jQuery
Save to your folder(s)

Selectors are ARRAYs ... so you should do something like this

$('div.a')[0] == $('div#a')[0]

or use the bellow method


Copy this code and paste it in your HTML
  1. $.fn.isEqual = function($otherSet) {
  2. if (this === $otherSet) return true;
  3. if (this.length != $otherSet.length) return false;
  4. var ret = true;
  5. this.each(function(idx) {
  6. if (this !== $otherSet[idx]) {
  7. ret = false; return false;
  8. }
  9. });
  10. return ret;
  11. };
  12.  
  13. var a=$('#start > div:last-child');
  14. var b=$('#start > div.live')[0];
  15.  
  16. console.log($(b).isEqual(a));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.