Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a text with jQuery

Tags:

jquery

I have an h1 with id of toptitle that is dynamically created, and I am not able to change the HTML. It will have a different title depends on a page. Now when it is Profile, I want to change it to New word with jQuery.

<h1 id="toptitle">Profile</h1> // Changing only when it is Profile   // to <h1 id="toptitle">New word</h1> 

Note: If the text is Profile, then change it to New word.

like image 431
shin Avatar asked Jun 20 '11 13:06

shin


People also ask

How do I set inner text in jQuery?

jQuery text() Method Tip: To set or return the innerHTML (text + HTML markup) of the selected elements, use the html() method.

How do I get paragraph text in jQuery?

$(function() { alert($("body"). find("a p"). text()); //or just $("a p"). text() });


1 Answers

This should work fine (using .text():

$("#toptitle").text("New word"); 
like image 132
Andrew Whitaker Avatar answered Sep 21 '22 15:09

Andrew Whitaker