I have a menu. Each anchor has it’s own class e.a. soup, salads, appetizers etc. I furthermore have a folder with different photo having the same name as the classes of the anchors e.a. soup.jpg, salads.jpg, appetizers.jpg etc. In my html I have a div holding a default background image. What I try to accomplish is that if a certain anchor is clicked the corresponding photo is loaded in div background. I have it working the following way:
But then I need to have a separate function for each anchor. I am sure there must be a way to get all the classes of the anchors and connect the corresponding photo to that anchor, but I have no idea how. I have been looking into getElementById and attr. but haven’t found the right answer as yet
Something like the above? The img_name variable should contain the class name of the anchor being clicked (hopefully) but it may need some playing around with. Do you have the full html of your anchor list?