May 07, 2021 jQuery
jQuery has a powerful way to manipulate HTML elements and properties.
A very important part of jQuery is the ability to operate the DOM.
jQuery provides a range of DOM-related methods that make it easy to access and manipulate elements and properties.
DOM - Document Object Model (Document Object Model)
DoM defines the criteria for accessing HTML and XML documents: "The W3C document object model is independent of the platform and language interface, allowing programs and scripts to dynamically access and update the content, structure, and style of the document." |
Three simple and practical jQuery methods for DOM operations:
text() - Set or return the text content of the selected element
html() - Set or return the contents of the selected element (including HTML tags)
val() - Set or return the value of the form field
The following example shows how to get content through jQuery text() and html() methods:
The following example shows how to get the value of an input field using the jQuery val() method:
The jQuery attr() method is used to get property values.
The following example shows how to get the value of the href property in the link:
The next chapter explains how to set (change) content and property values.
jQuery Reference Manual - Document operation