I have several a tags as shown below on a dynamically generated page
<a href='JavaScript:SWETargetGotoURL(vtUrl+"XRX+eCustomer+Account+Inventory+View", "_self")' id='s_ViewBar' name=s_ViewBar> Inventory </a>
I need to traverse through all the a tags containing the text "SWETargetGotoURL" in their href tag and depending on the text I need to add the title tag
for example
if(extractedtext == " Inventory ")
title = "This is inventory homepage";
The a tag should finally look like this
<a href='JavaScript:SWETargetGotoURL(vtUrl+"XRX+eCustomer+Account+Inventory+View", "_self")' title = "This is inventory homepage" id='s_ViewBar' name=s_ViewBar> Inventory </a>
I used following code to get all the tags with specific value in href tag but I am unable to get the text in between and I don't know how to run a loop and work on all the a tags
var screenName = $('a[href*="SWETargetGotoURL"]').attr('href');
Any help is really appreciated.
I think what you're looking for is $.each which iterates over the set of selected elements.
$('a[href*="SWETargetGotoURL"]').each(function () {
//get the text of the element
var extractedtext = $(this).text();
//check text for match
if (extractedtext == " Inventory ") {
//Change title attribute of element
$(this).attr('title', "This is inventory homepage");
}
});