I have content of a html file. I want in js to get all link that contain "do=download" in this page. How i can do that?
Asked
Active
Viewed 297 times
0
-
Please visit [help], take [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output, preferably in a [Stacksnippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) – mplungjan Feb 06 '22 at 08:55
-
If all your links are `` tags then you could get them all the text of the tags using `document.getElementsByTagName("a")` then iterate over each, getting their `.outerHTML` and checking the string using `includes`. – Liam Pillay Feb 06 '22 at 08:57
-
1@LiamPillay of just do `const aLinks = [...document.querySelectorAll("a[href*='do= download']")].map(lnk=>lnk.getAttribute("href"));` – mplungjan Feb 06 '22 at 09:03
-
1@mplungjan the more you know! Thanks for that. – Liam Pillay Feb 06 '22 at 09:04