Update text inside a div

How do I update <h2> text inside a particular div?

<div id="outerwrapper">
  <div id="wrapper>
    <h2></h2>
  </div>
</div>

$('#wrapper').text("new text");

Answers 1

  • Try this:

    $('#wrapper h2').html("new text");
    

    And you've missed a quotation here: <div id="wrapper>

    Code should be like this:

    <div id="outerwrapper">
        <div id="wrapper">
            <h2></h2>
         </div>
    </div>
    

Related Articles