Reputation: 1295
I have rows in this format:
<tr id="_ctl0_viewCompanies_companyRepeater_myresultsRow1_13" class="DGAlternatingItemStyle">
<td style="padding:0.5em;">
<a style="color: #8B0000; font-size: 1em; font-weight:normal;" href="http://mylinkhere?itemid=12367" target="_blank">some name text</a>
</td>
I know this part itemid=12367
in href is unique, how could I find the id of tr contains that itemid ? (the result should be: _ctl0_viewCompanies_companyRepeater_myresultsRow1_13
)
What I tried:
function getAllElementsWithAttribute()
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute("href"))
{
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
alert ( matchingElements );
}
But I not sure what else to do from there.
Upvotes: 1
Views: 1056
Reputation: 2111
Use jQuery ends with selecter
$('a[href$="itemid=12367"]').closest('tr').attr('id')
Upvotes: 2