So I got my code to work but it’s doing the opposite of what I want the code to do. I want the user to click the thumb image and the same larger image to pop up but when I load the page the larger image is shown and I don’t want that and also can I write an addEventListener for each image.
Javascript:
function nailHandler(evnt){
let chat = document.getElementById(‘bigChat’);
if(chat.className ===‘on’){
chat.className= ‘’;
}else{
chat.className =‘on’;
So I got my code to work but it’s doing the opposite of what I want the code to do. I want the user to click the thumb image and the same larger image to pop up but when I load the page the larger image is shown and I don’t want that and also can I write an addEventListener for each image.
Javascript:
function nailHandler(evnt){
let chat = document.getElementById(‘bigChat’);
if(chat.className ===‘on’){
chat.className= ‘’;
}else{
chat.className =‘on’;
Personally, I don’t like the idea of a new window. Use a predefined element in the current viewport and line up the the thumbs above, below, or down the side(s).
Now in your script, bind the listener to the parent class, “thumbs” and delegate the click events to the element that is clicked. The handler would be given the src attribute value of the target node and would then fashion a URL for the view image.
There is a URL posted in the code for where to find this code, and the explanation for it. That is why it is so important to document your code with attribution links, both for where it came from, and for the information that may have been forgotten in the passing of time.
Let’s say we have a list of clickable objects. Do we give each one an event binding? or just the group? Simple answer, the group. Then we have only one listener and use way less memory and resources to manage it.
The above function is the engine that drives delegation. When a click (or other event) is fired on an element in the group, the handler calls this function first to find out which one it is. The returned object is the target element. Now we can identify the actual element, its properties and if there is one, its associated callback function.
In the above code the same code runs for every thumbnail click, only with the specific data associated, in this case, the URI to the large image. The current image is removed from the viewer, and the new one inserted into the DOM to take its place.