In Action

Retrieve HTML Text using JQuery - Equivalent to javascript innerHTML

With jquery it is easy to retrieve the text from within an html tag.

This is a paragraph tag. Click button to see text, then review code.




JQuery Code

JQuery Code for our example

To retrieve the text contained within an html tag we only need to use the text() function for the desired html tag.

	$(document).ready(function() {
     $("#doit").click(function(){
	   	 var ihtml = $("#ptag").text();
     	  alert(ihtml);
     });	
	});	

HTML Code

HTML Code for our example

	<p id="ptag">This is a paragraph tag. Click button to see text, then review code.</p>
	<br />
  <button id="doit">Get the text</button>

It is also possible to append or rewrite text within an html tag.