dimanche 17 juillet 2016

How to get an href within a HTML element?

I'm looping through a list of objects like this:

for (var i=0;i<rows.length;i++) {
   console.log(rows[i].children[2])
}

and it's outputting html like this:

  <td style="padding-left: 1em">
    <a href="/assets/images/royce/royce-trumbull-09.jpg">royce-trumbull-09.jpg</a>
  </td>

And I'm simply trying to get the href attribute from each <td> like the one above. I tried rows[i].children[2].getAttribute("href") and rows[i].children[2].href among other things. I just want to return "/assets/images/royce/royce-trumbull-09.jpg"

Aucun commentaire:

Enregistrer un commentaire