How do I enumerate all of the html id's in a document with javascript?

前端 未结 8 791
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 07:54

I would like to be able to use javascript to find every id (or name) for every object in an html document so that they can be printed at the bottom of the page.

To under

8条回答
  •  萌比男神i
    2021-01-31 08:31

    well, since it is a form, im sure that you want to iterate only over the form elements and not all the tags in the document ( like href , div's etc.. )

    for (var i=0; i < form.elements.length; i++) {
       var elementId = form.elements[i].id;
    }
    

提交回复
热议问题