How to find any element by id of HTML document is exist or not ?
How to find any element by id of HTML document is exist or not ? using Javascript and Jquery ..
I want to use in form validation .. I check first element is exist or not
Javascript
jQuery
- asked 8 years ago
- Sunny Solu
2Answer
If mutation observes aren't an option due to their browser compatibility, you'll have to involve the code that's actually inserting the <div>
into the document
.
One options is to use a custom event as a pub/sub.
$(document).on('document_change', function () {
if (document.getElementById('liveGraph_id')) {
// do what you need here
}
});
// without a snippet to go on, assuming `.load()` for an example
$('#container').load('/path/to/content', function () {
$(this).trigger('document_change');
});
- answered 8 years ago
- Sunny Solu
If it is added dinamically, you have to test again. Let's say, a click event
$("#element").click(function()
{
if($("#liveGraph_id").length)
alert("HHH");
});
- answered 8 years ago
- Sunny Solu
Your Answer