Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if element exists [duplicate]

Possible Duplicates:
Is there an “exists” function for jQuery
jQuery determining if element exists on page

if(tr) is returning true when tr is not an element, how do I check whether it's an element that exists?

var tr = $('#parts-table .no-data').parent(); $('.delete', row).bind('click', function (e) {   that.delete(e.currentTarget); }); console.log(tr); if (tr) //returns true when it shouldn't 
like image 436
Webnet Avatar asked Jan 25 '11 16:01

Webnet


1 Answers

Check its length property:

if(tr.length) {     // exists } 

if(tr) always evaluates to true because a jQuery object, or any JavaScript Object for that matter, is always truthy.

like image 51
karim79 Avatar answered Sep 21 '22 01:09

karim79