var modal = document.getElementById('modal'); var img = document.getElementsByClassName('.image'); var modalImg = $("#modal-img"); var captionText = document.getElementById("modal-text"); $('.image').click(function(){ modal.style.display = "block"; var newSrc = this.src; modalImg.attr('src', newSrc); captionText.innerHTML = this.alt; }); var span = document.getElementsByClassName("close-x")[0]; span.onclick = function() { modal.style.display = "none";
document.getElementById
$("#MyTextBox")
ocument.getElementById("MyTextBox")
Quote:How about everything to jQuery? What does that code look like?
var modal = $('#modal'); var img = $('.image'); var modalImg = $("#modal-img"); var captionText = $("#modal-text"); img.click(function(){ modal.show(); var newSrc = this.src; modalImg.attr('src', newSrc); captionText.html( this.alt); }); var span = $(".close-x"); span.click( function() { modal.hide(); }
var modal = $('#modal'); // ID Selector var img = $('.image'); // Class selector var modalImg = $("#modal-img"); // ID selector var captionText = $("#modal-text");// ID selector img.click(function(){ // click function delegate modal.show(); // jquery function to show var newSrc = this.src; // get src attribute from anchor tag modalImg.attr('src', newSrc); // set src for new image captionText.html( this.alt); // add text to the modal-text control from the iamge alt attribute }); var span = $(".close-x"); // class selector span.click( function() { // click event modal.hide(); // jquery function to show }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)