jQuery
HTML
CSS
JavaScript
PHP
SQL
WordPress
jQuery Tutorials

Overview

jQuery contains a multitude of DOM-related methods that make it easy to access and manipulate HTML elements and attributes.

The following are some quick examples of the methods used to manipulate page elements. A complete list of DOM-related methods can be found here along with more detailed descriptions of their intended use and syntax.

addClass() Method

The addClass() method adds one or more class names to the selected elements.

				
					// add a .content class to all paragraphs
$('p').addClass('content');
				
			

append() Method

The append() method inserts specified content (HTML tags, jQuery objects, DOM elements) at the end of the selected elements.

				
					// add content before every paragraph's closing tag
$('p').append('<p>Hello World</p>');
				
			

attr() Method

The attr() method sets attributes and values of the selected elements.

				
					// adds and sets the width for images
$('img').attr('width', '80');
				
			

css() Method

The css() method sets one or more style properties for the selected elements.

				
					// set color property for all paragraphs
$('p').css('color', 'red');
				
			

html() Method

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

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

prepend() Method

The prepend() method inserts specified content (HTML tags, jQuery objects, DOM elements) at the beginning of the selected elements.

				
					// add content just after every paragraph's opening tag
$('p').prepend('<p>Hello World</p>');
				
			

removeAttr() Method

The removeAttr() method removes one or more attributes from the selected elements.

				
					// removes the color attribute from all paragraph elements
$('p').removeAttr('color');
				
			

removeClass() Method

The removeClass() method removes one or more class names from the selected elements. If no parameter is specified, this method will remove ALL class names from the selected elements.

				
					// removes the .section class from all paragraph elements
$('p').removeClass('section');
				
			

text() Method

The text() method sets the text content of the selected elements, overwriting the content of ALL matched elements. This only replaces the text inside the element and does NOT remove the elements tags or attributes.

				
					// replace the text within all paragraph elements
$('p').text('Hello world');
				
			

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.

jQuery
HTML
CSS
JavaScript
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.