Checking if jQuery variable is referring to a specific DOM element -
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'); } });
Comments
Post a Comment