简体   繁体   中英

how to get value of element which have particular class and id?

i want to get transform attribute of particular id and class using java script not jquery? is there any solution to select a specific element, specifying both the class and id ? for example:

 <g id="748588" transform="translate(44 -4)" class="Selection"></g>

And I want to get transform attribute corresponding with match id and class

You can use document.querySelector()

const selector = document.querySelector("#748588.Selection")
const transformValue = selector.getAttribute("transform")

Yes, document.querySelector will do what you want. Here is the MDN page. In your case, you could use something like:

const my_transform = document.querySelector('#748588.Selection').getAttribute('transform')

使用getElementById获取元素,然后可以从元素style对象中获取transform属性:

document.getElementById("748588").style.transform

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM