Milksamsa
Milksamsa

Reputation: 319

Pass variable as parameter in jquery .load

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

Answers (2)

Rakesh Kumar
Rakesh Kumar

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

Karl-André Gagnon
Karl-André Gagnon

Reputation: 33870

A simple string concatenation:

 $('.bio').load('/people/index.html .'+ elementClass, function(){})

Upvotes: 1

Related Questions