search

Home  >  Q&A  >  body text

html - How JavaScript's Dom manipulation changes the text content of child elements

Why can't the following code change "Hello" in the p tag to "Hello everyone"?

某草草某草草2827 days ago749

reply all(2)I'll reply

  • 为情所困

    为情所困2017-05-24 11:38:57

    getElementsByTagName The function returns a DOM collection:

    cont[0].innerHTML = 'Hello'

    reply
    0
  • 黄舟

    黄舟2017-05-24 11:38:57

    getElementById returns a value, while getElementsByName returns a collection.
    id is unique, name can be the same.

    reply
    0
  • Cancelreply