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

前端 未结 8 715
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  清歌不尽
    2021-01-31 08:36

    The jQuery selector $('[id]') will get all the elements with an id attribute:

    $('[id]').each(function () {
        do_something(this.id);
    });
    

    Working example here: http://jsfiddle.net/RichieHindle/yzMjJ/2/

提交回复
热议问题