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:
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
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
class="michiel, link" ^^------- Remove this
Supposed to be
OR .. If you want the comma to be present , then change your selector to
var current = "img." + $(naam).attr('id') + "\\,";
But this is not recommended
naam is not defined. I made a jsfiddle here and looked in the chrome console.
$('.michiel').css('border', 'solid 4px #9966FF'); If you need it to be more specific, I'm sure you can take it from here.