[英]How to find table row id when knowing href of td contains specific text by javascript
我有這種格式的行:
<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>
我知道href中的itemid=12367
這部分是唯一的,如何找到包含該itemid的tr的ID? (結果應為: _ctl0_viewCompanies_companyRepeater_myresultsRow1_13
)我嘗試了什么:
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 );
}
但是我不確定從那里還能做什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.