Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  181] [ 6]  / answers: 1 / hits: 169138  / 14 Years ago, sun, march 13, 2011, 12:00:00

I know that you can test for width() or height() but what if the element's display property is set to none? What other value is there to check to make sure the element exists?


More From » jquery

 Answers
37

You can use length to see if your selector matched anything.



if ($('#MyId').length) {
// do your stuff
}

[#93303] Friday, March 11, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tammyb

Total Points: 278
Total Questions: 101
Total Answers: 103

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
;