How to access HTML element without ID?

后端 未结 6 1543
暖寄归人
暖寄归人 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条回答
  •  猫巷女王i
    2020-11-30 06:17

    The simplest way of doing it with your current markup is:

    document.getElementById('header-inner').getElementsByTagName('h1')[0].innerHTML = 'new text';

    This assumes your H1 tag is always the first one within the 'header-inner' element.

提交回复
热议问题