Call Specific Javascript/Jquery Function On multiple Images without using id or class attribute -


i trying create responsive modal images (images enlarge/popup when clicked).

i need able call onclick event on each image within div. however, images not have id or class attributes associated. because images uploaded via text editor through content management system.

is there way implement w3 schools modal images solution without use of ids , classes? (note: need work multiple images within div)

https://www.w3schools.com/howto/howto_css_modal_images.asp

<!doctype html>  <html>  <head>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>  <style>  #myimg {      border-radius: 5px;      cursor: pointer;      transition: 0.3s;  }    #myimg:hover {opacity: 0.7;}    /* modal (background) */  .modal {      display: none; /* hidden default */      position: fixed; /* stay in place */      z-index: 1; /* sit on top */      padding-top: 100px; /* location of box */      left: 0;      top: 0;      width: 100%; /* full width */      height: 100%; /* full height */      overflow: auto; /* enable scroll if needed */      background-color: rgb(0,0,0); /* fallback color */      background-color: rgba(0,0,0,0.9); /* black w/ opacity */  }    /* modal content (image) */  .modal-content {      margin: auto;      display: block;      width: 80%;      max-width: 700px;  }    /* caption of modal image */  #caption {      margin: auto;      display: block;      width: 80%;      max-width: 700px;      text-align: center;      color: #ccc;      padding: 10px 0;      height: 150px;  }    /* add animation */  .modal-content, #caption {          -webkit-animation-name: zoom;      -webkit-animation-duration: 0.6s;      animation-name: zoom;      animation-duration: 0.6s;  }    @-webkit-keyframes zoom {      {-webkit-transform:scale(0)}       {-webkit-transform:scale(1)}  }    @keyframes zoom {      {transform:scale(0)}       {transform:scale(1)}  }    /* close button */  .close {      position: absolute;      top: 15px;      right: 35px;      color: #f1f1f1;      font-size: 40px;      font-weight: bold;      transition: 0.3s;  }    .close:hover,  .close:focus {      color: #bbb;      text-decoration: none;      cursor: pointer;  }    /* 100% image width on smaller screens */  @media screen , (max-width: 700px){      .modal-content {          width: 100%;      }  }  </style>  </head>  <body>    <h2>image modal</h2>  <p>in example, use css create modal (dialog box) hidden default.</p>  <p>we use javascript trigger modal , display current image inside modal when clicked on. note use value image's "alt" attribute image caption text inside modal.</p>    <img id="myimg" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:and9gctbprncs_cusda0su-zhtzbji3jyxunvxswsrbktgw6qq4vausocyjr0vjl" alt="trolltunga, norway" width="300" height="200">    <!-- modal -->  <div id="mymodal" class="modal">    <span class="close">&times;</span>    <img>    <div id="caption"></div>  </div>    <script>    var modal = document.getelementbyid('mymodal');  var captiontext = document.getelementbyid("caption");      $("img").click(function(){   modal.style.display = "block";   var img=this.src;   $("#mymodal img").attr("src",img);   $("#mymodal img").attr("width","100%");    captiontext.innerhtml = this.alt;  });      var span = document.getelementsbyclassname("close")[0];    span.onclick = function() {       modal.style.display = "none";  }  </script>    </body>  </html>


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -