[英]Get element id name on html element
我們如何獲得dom元素id名稱? 我知道我們可以使用 document.getElementById('test'); 獲取元素 ID 如下例所示。
Html代碼
<html>
..
..
<table id = 'test'>
<tr id='test'> </tr>
</table>
</html>
示例:知道 id 是“test”,而不是指定 get document.getelementbyid(..),我試圖在沒有 document.getelementbyid 方法的情況下獲取 id 名稱
示例用例
const getid = d3.select('table')
//this will return the html tag, this point i am trying to retrieve the id name.
//i have tried
getid.id , getid.getDocumentById() .
這甚至可以用 JS 實現嗎?
試試d3.select('table').attr("id")
https://github.com/d3/d3-selection/blob/v2.0.0/README.md#selection_attr
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.