![](/img/trans.png)
[英]how to get value of particular element when clicked on button which is having same class
[英]how to get value of element which have particular class and id?
我想使用 java 腳本而不是 jquery 獲取特定 id 和 class 的轉換屬性? 是否有任何解決方案來選擇特定元素,同時指定 class 和 id ? 例如:
<g id="748588" transform="translate(44 -4)" class="Selection"></g>
我想獲得與匹配 id 和 class 對應的轉換屬性
const selector = document.querySelector("#748588.Selection")
const transformValue = selector.getAttribute("transform")
是的, document.querySelector
會做你想做的。 這是 MDN 頁面。 在您的情況下,您可以使用以下內容:
const my_transform = document.querySelector('#748588.Selection').getAttribute('transform')
使用getElementById獲取元素,然后可以從元素style
對象中獲取transform
屬性:
document.getElementById("748588").style.transform
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.