javascript 遍历DOM

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 遍历DOM相关的知识,希望对你有一定的参考价值。

$("#demo").parent();                // accessing direct parent
$("span").parent().hide();          // changing parent color
$("#demo").parents();               // all ancestors of the element
$("#demo").parentsUntil("#demo2");  // all ancestors between two - demo is inside demo2
$("#demo").children();              // all direct children
$("#demo").children(".first");      // all direct children having a specified class
$("#demo").find("span");            // all span elements inside #demo
$("#demo").find("*");               // all descendants
$("#demo").siblings("span");        // span siblings of #demo
$("#demo").next();                  // the next sibling
$("p").nextAll();                   // all next siblings
$("#demo").nextUntil("#demo2");     // siblings between two arguments
$("#demo").prev();                  // the previous sibling
$("p").prevAll();                   // all previous siblings
$("#demo").prevUntil("#demo2");     // previous siblings between two arguments

以上是关于javascript 遍历DOM的主要内容,如果未能解决你的问题,请参考以下文章

使用JavaScript从组件外部遍历本地DOM

javascript 遍历DOM

javascript 遍历DOM

markdown JavaScript遍历Dom,获取元素

JavaScript DOM遍历辅助函数

JavaScript之DOM-4 文档结构和遍历(节点树元素树文档的遍历)