This question already has an answer here:
- Is there an “exists” function for jQuery? 40 answers
How do I check if an element exists if the element is created by .append()
method?
$('elemId').length
doesn't work for me.
This question already has an answer here:
How do I check if an element exists if the element is created by .append()
method?
$('elemId').length
doesn't work for me.
Try to check the length of the selector, if it returns you something then the element must exists else not.
You need to put
#
before element id:With vanilla JavaScript, you don't need the hash (
#
) e.g.document.getElementById('id_here')
, however when using jQuery, you do need to put hash to target elements based onid
just like CSS.