Gaurav Raj

Gaurav Raj

  • 1.4k
  • 475
  • 36k

unable to set property 'onclick' of undefined

Feb 2 2018 4:41 AM
unable to set property 'onclick' of undefined and img
 
please help me
 
THIS is my modal.js file code
  1. // Get the modal  
  2. var modal = document.getElementById('myModal');  
  3. // Get the image and insert it inside the modal - use its "alt" text as a caption  
  4. var img = document.getElementById('<%= ImgProfile.ClientID %>');  
  5. var modalImg = document.getElementById("img01");  
  6. //var captionText = document.getElementById("caption");  
  7. img.onclick = function () {  
  8. alert("hello");  
  9. modal.style.display = "block";  
  10. modalImg.src = this.src;  
  11. // captionText.innerHTML = this.alt;  
  12. }  
  13. // Get the <span> element that closes the modal  
  14. var span = document.getElementsByClassName("close")[0];  
  15.   
  16. // When the user clicks on <span> (x), close the modal  
  17. span.onclick = function() {  
  18. modal.style.display = "none";  
  19. }  
THIS is my home.aspx file code
  1. <asp:Image ID="ImgProfile" runat="server" src="Images/19251082_10215259476544325_53831408_n.jpg" CssClass="img-thumbnail"/>  
  2. <div id="myModal" class="modal">  
  3. <span class="close">×</span>  
  4. <img class="modal-content" id="img01" />  
  5. <div id="caption"></div>  
  6. </div>  

Answers (2)