Let's say that I have a website and I want to use script that loops trough its DOM elements and points out these elements that attribute contains part of specified text. I've managed to create a simple loop that finds every desired attribute of DOM element and creates array from it. Now I want to pair my array attribute value with DOM element that it belongs to and also be able to find out specified part of text that matches the array element (attribute) and DOM element.
var getAll = document.getElementsByTagName('*');
var myArray = [];
for (var i=0; i<getAll.length; i++) {
getHref = getAll[i].getAttribute('href');
if (getHref !== null) {
myArray.push(getHref);
}
}
I have no clue how to link my attributes with DOM elements. I've tried to use indexOf('') to find part of text but it doesn't work since it looks for full strings in array. Would anybody be so nice and help me out? I don't want to use any frameworks.