最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Get nested element by tag->id->element with javascript - Stack Overflow

programmeradmin0浏览0评论
document.getElement(div#menuArea).getElements(a)

I want to get all the a elements from a div with id "menuArea". I think above syntax is wrong. Can anyone point me in the right direction?

document.getElement(div#menuArea).getElements(a)

I want to get all the a elements from a div with id "menuArea". I think above syntax is wrong. Can anyone point me in the right direction?

Share Improve this question edited Jul 4, 2016 at 14:15 Andrei Maieras asked Feb 26, 2015 at 7:37 Andrei MaierasAndrei Maieras 7065 gold badges16 silver badges36 bronze badges 1
  • 1 You should research for answers before asking. stackoverflow.com/questions/15765639/… – NewToJS Commented Feb 26, 2015 at 7:40
Add a comment  | 

2 Answers 2

Reset to default 14

Try this

document.getElementById('menuArea').getElementsByTagName('a')

Or for IE8+

document.querySelectorAll('#menuArea a')

Or you can try jQuery:

$('#'menuArea a');

About class, try this:

var d = document.getElementById('menuArea').getElementsByTagName('a')
d.className = d.className + " otherclass";

This is pure JavaScript.

发布评论

评论列表(0)

  1. 暂无评论