switz
switz

Reputation: 25188

Click the next element

There's a div with the id "element" and within it is an anchor tag. I need to find the element, then get the anchor tag on the inside and click it purely through javascript. (no jquery).

How might I do this?

Upvotes: 0

Views: 312

Answers (1)

Phrogz
Phrogz

Reputation: 303261

var e = document.getElementById('element');
var a = e.getElementsByTagName('a')[0];
a.click();

Or as a one-line:

document.getElementById('element').getElementsByTagName('a')[0].click();

Upvotes: 1

Related Questions