-6

I want to know what javascript code I can use to edit the text of this word? This is not a duplicate because this has multiple divs in a div. And the target word is located in a div that is inside the more divs.

<div id="jump">
  <div class="kick">
     <div class="meet">
        <div class="balls">
           <div class="word">
             Hello
          </div>
       </div>
   </div>

  • 1
    You've put almost no effort into this question – Isaac Jan 22 '18 at 21:22
  • he who googles well rules the world – Cruiser Jan 22 '18 at 21:22
  • 2
    Use a text editor. No javascript required. – Marc Jan 22 '18 at 21:22
  • What are you guys talking about? – Mark Binder Jan 22 '18 at 21:23
  • What is the javascript code to replace the word? – Mark Binder Jan 22 '18 at 21:23
  • 2
    Welcome to StackOverflow! Have you tried anything so far? StackOverflow isn't a free code-writing service, and expects you to [**try to solve your own problem first**](http://meta.stackoverflow.com/questions/261592). Please update your question to show what you have already tried, showcasing a **specific** problem you are facing in a [**minimal, complete, and verifiable example**](http://stackoverflow.com/help/mcve). For further information, please see [**how to ask good questions**](http://stackoverflow.com/help/how-to-ask), and take the [**tour of the site**](http://stackoverflow.com/tour). – Obsidian Age Jan 22 '18 at 21:24

2 Answers2

0

You can use next code:

document.querySelector('.word').textContent = 'Hello World!';
<div id="jump">
  <div class="kick">
     <div class="meet">
        <div class="balls">
           <div class="word">
             Hello
          </div>
       </div>
   </div>

But if you has few elements with class word, function 'querySelectror fining only first element'.If you need get many elements, you can use document.querySelectorAll --- is HTMLCollection (not array). I don't recommend to use getElementByClassName - is very slowly method. Method getElementsByTagName -faster that querySelectorAll , but it use only tagName. getElementById -is the fastest menthod finding of elements. But that method find only first element with current ID.

Petrashka Siarhei
  • 733
  • 10
  • 12
0

It's the 1st element that has this class...

document.getElementsByClassName('word')[0].innerHTML='Goodbye';

It's the 5th element that has this tag...

document.getElementsByTagName('div')[4].innerHTML='Goodbye';
user4723924
  • 142
  • 4