简体   繁体   English

如何使用javascript获取标签属性?

[英]How to get attribute of tag using javascript?

Sorry if my question was stupid. 对不起,如果我的问题很愚蠢。 please someone one tell me how to do this following issue. 请有人告诉我下一个问题该如何做。 I have tags like shown below 我有如下所示的标签

<link rel="next" href="#" >
<link rel="prev" href="#" >

now i need to select this tag by using where rel has next and where tag rel has prev eg: rel="next" 现在,我需要使用rel具有下一个位置和rel具有上一个位置的位置来选择此标签,例如: rel="next"

getElementbyAttribute(rel="next").href ="www.yyyy.com"

getElementbyAttribute(rel="prev").href ="www.mmmm.com"

How to do this in javascript 如何在javascript中做到这一点

您可以使用document.querySelectordocument.querySelectorAll来获取所有匹配的元素:

document.querySelector("[rel='next']");

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

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