简体   繁体   English

如何获取具有特定类和 id 的元素的值?

[英]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?我想使用 java 脚本而不是 jquery 获取特定 id 和 class 的转换属性? is there any solution to select a specific element, specifying both the class and id ?是否有任何解决方案来选择特定元素,同时指定 class 和 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我想获得与匹配 id 和 class 对应的转换属性

You can use document.querySelector()您可以使用document.querySelector()

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

Yes, document.querySelector will do what you want.是的, document.querySelector会做你想做的。 Here is the MDN page. 是 MDN 页面。 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击具有相同类的按钮时如何获取特定元素的值 - how to get value of particular element when clicked on button which is having same class 如何获取inner的值, <span>除了parent div值之外,该</span>值<span>没有id或class的选择器?</span> - how to get value of inner <span> ,which does not have id or class slectors except parent div value? 如何获取我单击的特定表单的输入字段的值,所有 forms 及其输入具有相同的 class 但值不同 - How to get the value of input fields of a particular form on which i clicked ,all the forms and their input have the same class but different value 如何获取具有特定类的多个元素ID - How to get multiple element id's that have a specific class 如何使用jQuery通过ID查找特定的祖父母并通过某些类获取其特定孩子的价值 - How to find a particular grand parent by Id and get value of its particular children by certain class using jQuery 如何通过javascript获取特定坐标处元素的ID - How to get ID of an element at a particular coordinate by javascript 根据特定属性的值获取元素的类或ID名称 - Getting class or ID name of an element based on the value of a particular attribute 如何通过非直接类获取父元素的 ID 值? jQuery - How to get the ID value of a parent element by class that is not immediate? jQuery 如何通过jQuery获取html中具有特定类的第一个元素的ID值 - How to get ID value of first element with specific class in html by jQuery 如何选择所有具有特定模式ID的Textareas - How to select all the Textareas which have their id in a particular pattern
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM