使用jQuery遍历所有DOM元素

Posted

tags:

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

This code will walk all elements from a given selector.
  1. function doStuff(child, type) {
  2. if(typeof type !== 'undefined' && type != ""){
  3. /** HERE **/
  4. }
  5. }
  6.  
  7. function walk(children){
  8. if (typeof children == "undefined" || children.size() === 0) {
  9. return;
  10. }
  11.  
  12. children.each(function(){
  13. var child = $(this);
  14. if (child.children().size() > 0) {
  15. walk(child.children());
  16. }
  17. doStuff(child, this.type);
  18. });
  19. }
  20.  
  21. walk($("#ka-registration-vital-information-form .participant"));

以上是关于使用jQuery遍历所有DOM元素的主要内容,如果未能解决你的问题,请参考以下文章