iterate through nested form elements in jquery

前端 未结 4 1262
长发绾君心
长发绾君心 2021-01-03 06:08

im sorry if this was posted already i have been looking to no avail..

I just want to know how to loop through nested form \'elements\' (elements being not only the s

4条回答
  •  孤城傲影
    2021-01-03 06:43

    You can use contents() (and filter out text nodes if needed) or find('*') to get all elements, though I dislike the use of wildcards.

     $('form').contents()
              .filter( function() { return this.nodeType == 1; } )
              .each(...);
    

    or

     $('form').find('*')
              .each(...);
    

提交回复
热议问题