如何用href =“#xyz”选择所有标签

时间:2010-10-04 10:44:45

标签: javascript events css-selectors

使用纯JavaScript我可以用href =“#xyz”选择所有标签。而且我也希望在点击该元素时触发一些事件......

我该怎么做?

PS:纯javascript意味着不使用jquery或其他框架

1 个答案:

答案 0 :(得分:2)

for (i=0;i<=document.links.length;i++) {
  if (document.links[i].href == '#xyz') {
    // here you will have "selected only the ones with #xyz
    // Just be careful with the test, it will require a http://..../ I believe
  }
}
相关问题