Recently, I stumbled upon this code for listing the hrefs of a website. However, now I want to filter it.
var arr = [], l = document.links;
for(var i=0; i<l.length; i++) {
arr.push(l[i].href);
}
alert(arr);
I am looking to modify this code to display only links that contain specific text within them.
For instance, I would like to show in an alert only links that contain ?day=20
, ?day=22
, or ?day=25
.
I attempted to add an if statement before .push, but unfortunately, it didn't work as expected and resulted in a blank alert message.
Lastly, is there a way to open each link in a new tab instead of displaying them in an alert? If so, any guidance on how to achieve this?