jQuery provides methods for changing and manipulating HTML elements and attributes.
jQuery DOM Manipulation:
One very important part of jQuery is the probability to manipulate the DOM. The jquery contains a group of DOM related methods to easily access and manipulate elements and attributes.
What is DOM(Document Object Model)?
The DOM is used to define a standard for accessing HTML and XML documents:
“The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.”
Get Content using text(), html(), and val()
jQuery methods for DOM manipulation are:
text() - It sets or returns the text content of selected elements
html() - It sets or returns the content of selected elements including HTML markup
val() - It sets or returns the value of form fields
The following example shows how to get content with the jQuery text() and html() methods.
The jQuery method attr(), provides a callback function. It has two parameters, the index of the current element in the list of selected elements and the original (old) attribute value. You can return the string you want to use as the new attribute value from the function.
The following example shows attr() with a callback function:
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok