There is a list I have with 7 entries. On the picture below you can see the area which I marked purple: 6 entries. You see the area which I marked blue, all the 7 entries got the same <a class "FPmhX notranslate MBL3Z".
My question is how can I get the href of each entry and store them all in a list/array? In this example, the href of first entry is /foo.96/.
If my question is not clear please tell me and I will try to describe it differently! :)
Create parent element of list in html and in your javascript write:
var links = document.querySelectorAll("a.FPmhX.notranslate.MBL3Z");
var list = document.querySelector("ul#linkList");///Your path to parent
for(var i=0;i<links.length;i++){
list.innerHTML += "<li>" + links[i].href + "</li>";
}
Or if you want to get the pathname then use links[i].pathname instead of links[i].href.
Here's the snippet
var links = document.querySelectorAll("a.FPmhX.notranslate.MBL3Z");
var list = document.querySelector("ul#linkList");
for(var i=0;i<links.length;i++){
list.innerHTML += "<li>" + links[i].href + "</li>";
}
<a href="https://www.w3schools.com/" class="FPmhX notranslate MBL3Z"></a>
<a href="https://developer.mozilla.org/en-US/" class="FPmhX notranslate MBL3Z"></a>
<a href="https://stackoverflow.com/questions" class="FPmhX notranslate MBL3Z"></a>
<a href="https://css-tricks.com/" class="FPmhX notranslate MBL3Z"></a>
<ul id="linkList">
Links:
</ul>
Is it helpful? :)