1

This works:

$('a[href$="' + currenturl2 + '"]').css("font-family", "\'Apercu Bold\'");

But there's two links on the page with that (variable) href. How do I apply it to one of them?

I've tried:

$('li a[href$="' + currenturl2 + '"]').css("font-family", "\'Apercu Bold\'");

And:

$('#recent-posts a[href$="' + currenturl2 + '"]').css("font-family", "\'Apercu Bold\'");

(where #recent-posts is the ul of the li s)

And:

$('#tunesID a[href$="' + currenturl2 + '"]').css("font-family", "\'Apercu Bold\'");

(where #tunesID is the parent element of the URL)

codingrose
  • 15,563
  • 11
  • 39
  • 58
user1951962
  • 125
  • 1
  • 14

2 Answers2

3

The eq function can be used to reduce the set of selected elements to the one at the specified index. Just specify 0 or 1 for the a you want to select.

$('a[href$="' + currenturl2 + '"]').eq(0).css("font-family", "\'Apercu Bold\'");
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • Many thanks for your help, it works. And if any other JQuery novices (like me) have the same problem and are reading this but are still stuck, make sure that you've got your attribute selector right (as I didn't at first)... Simple breakdown of those on this page: http://stackoverflow.com/questions/303956/select-a-which-href-ends-with-some-string – user1951962 Jan 07 '14 at 18:10
-1

give to this links same class and in jquery code

$(".class").click(function(){
      $(this).css("font-family", "\'Apercu Bold\'");
});
radouane
  • 26
  • 3