Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
jQuery provides a powerful set of methods to dynamically change and manipulate HTML content, elements, and attributes and making it super easy to build interactive web pages.
DOM manipulation lets you interact with and dynamically change HTML content, structure, and styles without reloading the page.
With just a few lines of jQuery, you can:
Three simple, but useful, jQuery methods for DOM manipulation are:
Method |
Description |
Example |
---|---|---|
.text() |
Get the text content (plain text) |
$("#p1").text() |
.html() |
Get the HTML content (including tags) |
$("#p1").html() |
.val() |
Get the value of form elements |
$("#input1").val() |
The following example demonstrates how to get content with the jQuery text()
and html()
methods:
Try it yourself
The following example demonstrates how to get the value of an input field with the jQuery val()
method:
Try it yourself
Use .attr("attributeName")
to get the value of any attribute.
The following example demonstrates how to get the value of the href attribute in a link:
Try it yourself