Reputation: 5817
I got a class name after I clicked a element in the document. And then I want to select all elements that has this selected class. For example;
$('.tabs1 li a').hover(function(){
var clicked = $(this).attr("class");
// this doesnt work
$('a[class="clicked"]').css("display","block");
});
Upvotes: 0
Views: 94
Reputation: 2810
It's true that the class
attribute can have multiple values. Like others, I'm guessing to an extent what the poster wants, but this at least allows for multiple classes (and accounts for spaces). If the poster's wanting to isolate just one of the classes, maybe that's another question or subquestion:
$('.tabs1 li a').hover(function(){
var clicked = $(this).attr("class");
clicked = clicked.replace(/(\s)+/g, '.');
// this should work
$('a.' + clicked).css({"display":"block", "background": "green"});
});
Upvotes: 3
Reputation: 262939
You can build a class selector from the class name:
var clicked = $(this).attr("class");
$("a." + clicked).css("display", "block");
Upvotes: 3