jQuery Reference

Quick Reference

The html() method sets the content (innerHTML) of the selected elements.

$('p').html();
// sets the content of all paragraphs to say Hello World!
$('p').html('<strong>Hello world!</strong>');

Syntax

Set the content:

$(selector).html(content)

Set the content using a function:

$(selector).html(function(index,currentcontent))

Note

It is generally good practice to place your jQuery code/function inside the document load function so that the action takes place ONLY after the document has finished loading. This ensures that all of the page elements that you may be selecting are in place before running the code on them.

Parameters

ParameterDescription
contentSpecifies the new content for the selected elements, and can contain HTML tags (required)
function(index,currentcontent)Specifies a function that returns the new content for the selected elements

  • index - returns the index position of the element in the set
  • currentcontent - returns the current HTML content of the selected element

jQuery Notes:

  • To use jQuery on your site, it must first be downloaded from the official jQuery site and linked to in your document <head>, or linked to via a CDN in your document <head>
  • It is generally good practice to place your jQuery code/function inside the document load function so that the action takes place ONLY after the document has finished loading
  • When using jQuery, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.