JQuery

How to check id is exists or not using jQuery?

How to check id is exists or not using jQuery?, someone asked me to explain?

In this article, I will show you how to check the element id is exists or not using jQuery. It probably will help in dynamic generated HTML elements, this simple example, check whether the id is there or not like this, 

<script type="text/javascript">

function savecomment() {

if ($("#txtcomment").attr("id")) {

         // ...           

 } else {

         // ...

        }

}

</script> <textarea name='textarea1' id='txtcomment' placeholder='Add acomment...' autocomplete='off' required='required' class='form-control custom-control' rows='3' style='resize:none'> </textarea> 

check id is exists or not using jQuery 

 

Post your comments / questions