Reputation: 5104
I'm developing a web application, need to append some text to a specific div(id=div_specific). The div is dynamic generated by program, so I need to verify if the div already exists, otherwise, I have to create that div first. How to verify if the div already exists?
Upvotes: 0
Views: 902
Reputation: 844
Simply:
if($("#mydivname").length) {
// do something cool with the div
} else {
// create it
$("#mydivparent").append("<div id='mydivname'>hello world</div>")
// now do something cool with the new div
}
Upvotes: 1
Reputation: 13853
This should do the trick,
if($('#' + div_specific).length == 1){
alert("I Exist");
}
Upvotes: 1