How to select the 2nd element of a type
Hi, I wrote the following jQuery script...and it's basically working. Note that it's in Drupal so the beginning and ending syntax is a little odd. Please focus on the content between $("A").each(function () { and });
- // used to change background-color of currently selected link
- (function ($, Drupal) {
- 'use strict';
- $("A").each(function () {
- if (this.href == document.URL) {
- $(this).parent().css("background-color", "#c03c03");
- $(this).css("color", "white");
- }
- });
- })(jQuery, Drupal);
The purpose of this, as is probably obvious, is to select the <div> that contains a link on the navigation bar, that matches the current url, and change it's background color and the link color.
However, I have TWO navigation menus on the page.
I only want this script to change the css properties on the 2ND of the two 'a' tags.
How can I target only this second 'a' tag (and parent)?