I just realized I screwed up the original HTML - the icon classes should not have been originally on the code. Now I understand the downvoting - along with the general sloppiness of the javascript. I've modified the HTML, making it what it should have been to start with.
I've got an unordered list that I'm searching through with jQuery to add a class to its anchor tag, depending on the text/innerHtml of the link that is in the list item:
<ul class="menu-items">
<li class="menu-item icon-globe">
<a href="/test/Mobile/Accounts.aspx" class="ui-link">Accounts</a></li>
<li class="menu-item icon-globe">
<a href="/dupont/Mobile/Transfers.aspx" class="ui-link">Transfers</a></li>
<li class="menu-item emailMenuItem icon-globe">
<a href="/test/Mobile/Messages.aspx" class="ui-link">Messages</a></li>
<li class="menu-item">
<a href="/test/CustomerService.aspx" class="ui-link">Alerts & Settings</a></li>
<li class="menu-item emailMenuItem icon-globe"><a href="/test/Mobile/DepositCheck.aspx" class="ui-link">Deposit a Check</a>
Her is the jQuery statement that should be adding the "AlertSettingIcon" class to the Alerts & Settings anchor tag:
$("li.menu-item a.ui-link").each(function() {
if ($( this ).innerHtml == "Accounts") {
$(this).addClass("AccountIcon");
} else
if ($( this ).innerHtml == "Transfers") {
$(this).addClass("TransferIcon");
} else
if ($( this ).innerHtml == "Messages") {
$(this).addClass("MessageIcon");
} else
if ($( this ).innerHtml == "Alerts & Settings") {
$(this).addClass("AlertSettingIcon");
} else
if ($( this ).innerHtml() == "Deposit a Check") {
$(this).addClass("RDCIcon");
}
else {
$(this).addClass("AlertSettingIcon");
}
});
When I use developer tools to examine the classes assigned to each anchor tag, the class does not get added. I've tried using .text(), wrapping my script in CDATA tags, .html(), using /u0026, and a couple of other methods, but I have yet to successfully add the class to the "Alerts & Settings" anchor element. I've also done each of these methods in both firefox and Chrome to ensure it's not browser compatibility.
Finally, here's a JSFiddle where the issue shows itself: https://jsfiddle.net/r7vnft5c/
Can anyone figure out why the AlertSettingIcon class is not being added as the JS/jQuery is written, and what I can do to fix it?
Thanks for your ideas, David