/ Published in: JavaScript
URL: http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_test_whether_an_element_exists.3F
From the jQuery documentation:
You can use the length property of the jQuery collection returned by your selector.
Note: It isn't always necessary to test whether an element exists. The following code would show the item if it exists, and do nothing (no errors) if it did not:
Expand |
Embed | Plain Text
if ( $('#myDiv').length ) { alert('#myDiv exists!'); }
You need to login to post a comment.
