Reputation: 10696
What it should do:
.box-wrapper
in the doc.tabs li a
.selected
and set class to empty stringthis
- clicked link and add .selected
And in the last step it is failing as you can see.
console.log( $('this').parent('li') ); = []
Why? What is wrong? Any suggestion much appreciated.
Upvotes: 2
Views: 48
Reputation: 342635
this
is an DOM object, not a selector string, so you need:
$(this).parent('li').addClass('selected');
console.log($(this).parent('li'));
instead of:
$('this').parent('li').addClass('selected');
console.log($('this').parent('li'));
$('this')
will cause jQuery to construct an object which wraps all elements matching your selector. 'this' is not a valid selector, so you get that 'selector unintelligible' error, whereas $(this)
refers to the jQuery-wrapped clicked anchor.
Upvotes: 6
Reputation: 6115
not sure what box wrapper has to do with it but this click function should work:
$(".tabs li a").click(function(){
$(".tabs li").removeClass("selected");
$(this).parent().addClass("selected");
}
Upvotes: 1