I`m trying to run different functions based on the image elements class name. The image elements are inside of link elements because, they are being used as thumbnails in a photo viewer div. My goal is to have a functions run when the On click function is ran for the photo viewer.
I want one function to run if the image has class Milk and a different function to run if the image has class Water.
So far I can access the image elements by class name but, when I try to set them to the functions they do not run. ex.
HTML
<div> <a><img class = Milk /> </a> </div>
Script
var drink = document.getElementsByClassName('Milk'); //gets the elements wanted. drink.onClick = function name; //does not run the function I set drink on click to.
Not sure if these have an effect but, I have a few other codes run on the link elements in the div. Adding classes, hide(), Fade(), and Delay() coding put on the links .
https://stackoverflow.com/questions/66037265/run-function-on-event-based-on-class-name February 04, 2021 at 07:29AM
没有评论:
发表评论