How do I add a value to the end of the text of a tag with a class using js?

  • 0
    Hello. I have a tag with a class price. How do I add letters to the end of the text of this tag. Is there some way to add letters to the end of the text of the price tag? I don't need innerHTML, because it completely overwrites the text, and I just need to add letters to the end of the text, and not overwrite the text.
    The text itself is like this - 1300r. Using js, I need to add letters to the end of the text - "ub." ... There is no way to change the text itself in the html code, because there is only one PHP code. It will turn out only with the help of js to somehow add letters to the end of the text. I will be very grateful.
    JavaScript Arabella Conrad, Dec 11, 2020

  • 2 Answers
  • 0
    I don't need innerHTML because it completely overwrites the text


    Well, so you can read, add and overwrite with an already added line.
    Anonymous

  • 0
    <p class="price">1300р</p>
    <script>
    let priceEl=document.querySelectorAll('.price')[0]
    priceEl.innerHTML+=yourString

    </script>

    просто добавлять ,а не перезаписывать
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!