如何使用javascript引用标记来填充数据?

时间:2018-04-19 05:15:15

标签: javascript html

如何引用div中存在的特定h4标记,而div又存在于div中,div也存在于div中以填充数组中的数据?

2 个答案:

答案 0 :(得分:0)

<div><div><div><h4 id="head"></h4></div></div></div>  
<script>
document.getElementById("head").innerHTML="some value";
</script>

答案 1 :(得分:0)

请检查一下。

function changeText() {
  //uncomment if want to use by tag id
    //document.getElementById('my_tag').innerHTML = "This is a new Heading";
    // if want to use by tag class name
    document.getElementsByClassName('my_tag')[0].innerHTML = "This is a new Heading";
  }
<div>
  <div>
    <div>
      <h4 id="my_tag" class="my_tag">This is a Heading</h4>
      <p>This is a paragraph.</p>
      <button onclick="changeText();">Click Me</button>
    </div>
  </div>
</div>