Text and HTML Methods

Published on: January 21, 2018

Welcome to tutorial number 2 of the Easy jQuery series part of EasyProgramming.net!

In this tutorial, we look at the various Text and HTML methods available to us including text(), html(), append(), and prepend(). These methods are used to both read from and write to HTML elements on the webpage. These are really useful methods to know and I cover how and when to use them. 

Here are some of the available jQuery Methods:

Method Description
$(selector).text() Read the inner text of the element if no parameters are passed. Ovverride inner text if passed with parameter.
$(selector).html() Read the inner HTML of the element if no parameters are passed. Ovverride inner HTML if passed with parameter.
$(selector).append("some text") Add text/HTML after the selector
$(selector).prepend("some text") Add text/HTML before the selector
$(selector).appendTo("some text") Add text/HTML inside the selector as the very first element
$(selector).prependTo("some text") Add text/HTML inside the selector as the very last element
$(selector).remove() Remove the selected HTML element

To fork the fiddle and follow along: https://jsfiddle.net/easyjs/aye39ajz/

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:



Comments: