Hi sperks,

I'm pretty sure you can do that by changing this line ...

$('div#searchLabels label.attr("for","' + selectedInput + '")').addClass("selected");

to this ...

$('#searchLabels label[for=' + selectedInput + ']').addClass("selected");

Instead of returning the attribute itself, you want to incorporate the attribute selector, [attribute=value], to the expression.

I also removed the "div" from in front of #searchLabels, because most likely there is no need for it.

Hope that helps.

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Dec 3, 2007, at 12:39 PM, sperks wrote:


I think that this bit of script is adding a class to the for
attribute, but I'm wanting to add the class to the element that has
that for attribute.  Can anyone help me do the targeting better?
Thanks

$(document).ready(function() {
        $('div#searchLabels').addClass('active'); // allows me to style the
radio buttons differently when JS is enabled
        $('div#searchLabels :radio[id]').click( function() {
                var selectedInput = $(this).text();
                $('div#searchLabels label').removeClass("selected");
                $('div#searchLabels label.attr("for","' + selectedInput +
'")').addClass("selected");
        });
});


Reply via email to