getNextElement函数的用法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了getNextElement函数的用法相关的知识,希望对你有一定的参考价值。
Usage of the getNextElement function. Very basic usage to pick out the h1 tags, then change the properties of the next element(not node).
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; }
以上是关于getNextElement函数的用法的主要内容,如果未能解决你的问题,请参考以下文章