I have the code snippet below:
<div id="mainMenuInternalMyProfile" class="mainMenuInternalTab" data-pagename="myprofile">
<div class="mainMenuInternalTabClickable"> </div>
<h4 class="mainMenuInternalTitle">MY PROFILE</h4>
<img src="images/main-menu-divider.png" class="mainMenuBackGroundDivider" alt="Dating Internal Menu Background Divider">
<img src="images/main-menu-selected.png" class="mainMenuBackSelected mainMenuBackSelectedOption" alt="Dating Internal Menu Selected">
</div>
The first line in the code contains data-pagename="myprofile"
. Similar HTML chunks exist with different data-pagename
attributes.
I want to identify and modify elements that match a specific data-pagename
value such as 'home' or 'myprofile'. Below is my attempt using jQuery:
var element = $('div.mainMenuInternalTab').find("[data-pagename='" + urlType + "']");
element.css({'color': '#000000','z-index':'100'});
I am uncertain about the correctness of my approach.
Should I target a higher-level parent DIV with an ID instead of using $('div.mainMenuInternalTab')
which has multiple instances?
Please advise, additional information can be provided if necessary.