Joackim Karlsson Joackim Karlsson - 2 years ago 113
Javascript Question

JavaScript click href without ID

I'm on a site where I would like to grab all the href links and click it. I know I could do this.

how ever, the issue is the href dosen't have an id, only a title. Can I somehow click all the href by it's title?

Answer Source

You can use document.querySelectorAll() with selector a[href] to retrieve all <a> elements having href attribute set, or [href] to retrieve all elements having an href attribute set; for..of loop to iterate collection

var hrefs = document.querySelectorAll("a[href]");
for (let elem of hrefs) {
  // do stuff
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download