window.onload = function() {
var headers = document.getElementsByTagName("h1");//grab all h1's
for(i=0; i<headers.length; i++) {//loop through the h1's
var elem = getNextElement(headers[i].nextSibling);//look for the next sibling of the h1
//apply these styles to the selected elements
elem.style.color = "red";
elem.style.backgroundColor = "black";
}
}
//getNextElement function
function getNextElement(node) {
if(node.nodeType == 1){
return node;
}
if(node.nextSibling) {
return getNextElement(node.nextSibling)
}
return null;
}