How to access HTML element without ID?

后端 未结 6 1532
暖寄归人
暖寄归人 2020-11-30 05:39

For instance in the snippet below - how do I access the h1 element knowing the ID of parent element (header-inner div)?

&
6条回答
  •  温柔的废话
    2020-11-30 06:18

    Here I get the H1 elements value in a div where the H1 element which has CSS class="myheader":

    var nodes = document.getElementById("mydiv")
                        .getElementsByTagName("H1");
    
    for(i=0;i

    Here is the markup:

    Hello

    I would also recommend to use jQuery if you need a heavy parsing for your DOM.

提交回复
热议问题