To check if an element exists in jQuery

Asked 2 years ago, Updated 2 years ago, 49 views

For example, if you add an element with .append(), how do you check if this element exists? `$('elemId').I did it with length, but it doesn't work.

javascript jquery

2022-09-22 22:09

2 Answers

You have to put # in front of the id.

$('#elemId').length
---^

Like this.


2022-09-22 22:09

You can check the existence of the element as below. We support you all.

null undefined NaN empty string ("") 0 false

if($("#lemId")){ // }

http://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in


2022-09-22 22:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.