Checking if jQuery variable is referring to a specific DOM element -


http://jsfiddle.net/vq062uhk/

var $currentrow = null;  $(function() {      $('.set').click(function() {         $currentrow = $(this).closest('tr');     });      $('.check').click(function() {         console.dir($(this).closest('tr'));          if ($currentrow == $(this).closest('tr')) {             alert('yes');         }         else {             alert('no');         }     }); }); 

i have table , variable called $currentrow refers current tr element. want able check if item (in case button "is current?") in current row.

i give tr's unique id's or attributes i'm wondering if can avoid that.

try following code,

$('.check').click(function(){     console.dir($(this).closest('tr'));     if ($currentrow && $currentrow.is($(this).closest('tr'))) {         alert('yes');     }     else {         alert('no');     } }); 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -