Jquery Cant Access Element With Its Attr Href // Simple Tabs Structure
I can't access 'a' element with its href. Like this example, i need add class to element which got href='#one' Here is jsFiddle. jQuery: //tabs part is working fine $('.tabs').hide
Solution 1:
Use attribute selector like so:
$('a[href="#one"]').addClass(...)
Also note that you defined a takE
variable and the you wrote take
: probably you may want to write
var takE = $('ul li'),
finD = takE.find('a[href="#one"]');
finD.addClass('thisisLink1');
Solution 2:
$('ul li a').each(function() {
if(this.href == link1) $(this).addClass('thisisLink1');
if(this.href == link2) $(this).addClass('thisisLink2');
if(this.href == link3) $(this).addClass('thisisLink3');
});
You can also use an object mapping:
var links = {
'#one': 'thisislink1',
'#two': 'thisislink2',
'#three': 'thisislink3',
};
$.each(links, function(key, val) {
$('ul li a[href="' + key + '"]').addClass(val);
});
Post a Comment for "Jquery Cant Access Element With Its Attr Href // Simple Tabs Structure"