top of page

Check if element exist in JavaScript or not

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • Jun 5, 2020
  • 1 min read

This would prevent unnecessary error on other pages of focus element not found.

 var elementExists = document.getElementById("closepopbtn");
   if(elementExists){
         document.getElementById('closepopbtn').onclick = function() {
      document.getElementById('popup').style.display = 'none'
    };
  }

Recent Posts

See All
Google ReCAPTCHA with AJAX

This is how you can pass on AJAX .js var userdata = { 'action' : 'signin_member', 'username' : jQuery('#user_name').val(), 'password' :...

 
 
 
Self Invoking Function jQuery

The function starts with (function ($) { and you can use your own code inside it (function ($) { jQuery(document).ready(function () {...

 
 
 
Smooth Scroll In JS and jQuery

jQuery(document).ready(function () { jQuery('.processreachfind').click(function(e){ e.preventDefault(); jQuery('html, body').animate({...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page