I’ve been looking for hours now why the following code won’t work:
naam = "div#" + $(naam).next('div').attr('id');
current = "img." + $(naam).attr('id');
$(current).css("border", "solid 4px #9966FF");
The div has an id with the same name as the class from the img:
<div id="michiel">
This is the image I want to use the code on:
<img src="Images/michielsmall.jpg" class="michiel, link" alt="Michiel">
As you can see I’m trying to change the border of the img with class "michiel".
When I console.log(current);, Output is: img.michiel, which is correct.
I really don’t know why this won’t work, please help.
That is because of the comma in the class name
Supposed to be
OR .. If you want the comma to be present , then change your selector to
But this is not recommended
Check Fiddle