Reputation: 319
I have an html DL list. Whenever I click on a DD, I would like to get its class name and pass it as a parameter to the Jquery .load function.
This is my code:
How do I change the .kilye class in order for it to get the class from the elementClass variable?
$('dd').click(function(){
$('#img').show();
var elementClass = $(this).attr("class");
$(this).toggleClass('active').siblings().removeClass('active');
$('.bio').load('/people/index.html .kilye', function(){
$('#img').hide();
$('.bio').slideToggle('slow');
});
});
Upvotes: 0
Views: 895
Reputation: 2853
Try this
$('dd').click(function(){
$('#img').show();
var elementClass = $(this).attr("class");
$(this).toggleClass('active').siblings().removeClass('active');
var url = '/people/index.html .'+elementClass;
$('.bio').load(url, function(){
$('#img').hide();
$('.bio').slideToggle('slow');
});
});
Upvotes: 1
Reputation: 33870
A simple string concatenation:
$('.bio').load('/people/index.html .'+ elementClass, function(){})
Upvotes: 1