Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Replace/Change The Heading Text Inside <h3></h3>, Using jquery?

How do I change/replace the <h3> text: "Featured Offers" using javascript to say "Public Offers" instead?

</div>  <!-- FEATURED OFFERS --> <div class="panel">    <div class="head">       <h3>Featured Offers</h3>    </div>    <div class="body">       <table>          <thead>             <tr> 
like image 525
James Freeberg Avatar asked Dec 18 '11 06:12

James Freeberg


People also ask

How do I change the header text in HTML?

Use the textContent property to change the text of a heading element, e.g. heading. textContent = 'Replacement heading text' . The textContent property will set the text of the heading to the provided string, replacing any of the existing content.

Which jQuery function is used to update the text of heading?

text() Replace text Replaces the text in the selected elements. Example: text("clicked") - Click on the heading text to change it. $(document). ready(function() { $("h1").

How to get text element in jQuery?

Answer: Use the jQuery text() method You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.


2 Answers

If you can select it, you can manipulate it.

Try this:

$(".head h3").html("your new header"); 

But as others mentioned, you probably want head div to have an id.

like image 164
Sergio Tulentsev Avatar answered Oct 09 '22 20:10

Sergio Tulentsev


you don't - not like this. give an id to your tag , lets say it looks like this now :

<h3 id="myHeader"></h3> 

then set the value like that :

myHeader.innerText = "public offers"; 
like image 25
barak ben horin Avatar answered Oct 09 '22 20:10

barak ben horin