获取标记名名称值 javascript [英] Get tagname name value javascript

查看:50
本文介绍了获取标记名名称值 javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从下面的代码行中获取 name 的标记名.我必须使用 javascript 从下面的标记名中获取名称

我需要webviewbounce

这是我所知道的.

document.getElementsByTagName("preference")

但它没有给我偏好名称.我想要的是 webviewbounce

名称的标记名

解决方案

使用 document.querySelector 获取元素.它将返回第一个匹配的元素.然后使用 getAttribute 从元素中获取所需的属性.如果有多个标签元素具有相同的 tagname ,使用 document.querySlectorAll

var getElem = document.querySelector('preference'),getNameProperty = getElem.getAttribute('name');console.log(getNameProperty)

<preference name="webviewbounce" value="false"/>

I'm trying to get the tagname of name from the below line of code. I have to get the name from the below tagname using javascript

<preference name="webviewbounce" value="false" />

i need to get webviewbounce

This is what i know.

document.getElementsByTagName("preference")

But it doesnt give me the preference name. What i want is the tagname of name which is webviewbounce

解决方案

Use document.querySelector to get the element. It will return the first matched element.Then use getAttribute to get the required attribute from the element. If there are multiple tag element with same tagname , use document.querySlectorAll

var getElem = document.querySelector('preference'),
  getNameProperty = getElem.getAttribute('name');
console.log(getNameProperty)

<preference name="webviewbounce" value="false" />

这篇关于获取标记名名称值 javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆