• support@answerspoint.com

How to find any element by id of HTML document is exist or not ?

3016

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

2Answer


0

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

0

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

    Facebook Share        
       
  • asked 8 years ago
  • viewed 3016 times
  • active 8 years ago

Best Rated Questions