4
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?

1

2 Answers 2

14

Try this

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

Or for IE8+

document.querySelectorAll('#menuArea a')
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I need to use only JS. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.