Tuesday, 10 September 2013

How to check if an element with id exists or not in jQuery?

How to check if an element with id exists or not in jQuery?

I'm generating a div dynamically and I've to check whether a dynamically
generated div exists or not ? How can I do that?
Currently I'm using the following which does not detects the div generated
dynamically. It only detects if there is already an element with the id
contained in the HTML template.
$(function() {
var $mydiv = $("#liveGraph_id");
if ($mydiv.length){
alert("HHH");
}
});
How can I detect the dynamically generated div?

No comments:

Post a Comment