jQuery Tutorials
jQuery Effects
jQuery HTML
jQuery Traversing
jQuery AJAX
jQuery Misc
JQuery contains powerful ways to modify and manipulate HTML elements and attributes.
The most important part of jQuery is that it is possible to use DOM.
JQuery comes with a number of DOM-related features that make it easy to access and trick elements and attributes.
DOM = Document Object Model
DOM defines the level of access to HTML and XML documents:
"The W3C Document Object Model (DOM) is a platform with a virtual interface that allows programs and documents to dynamically access and update content, structure, and style of text."
Three simple, but useful, jQuery methods for DOM manipulation are:
text()
- Sets or returns the text content of selected elementshtml()
- Sets or returns the content of selected elements (including HTML markup)val()
- Sets or returns the value of form fieldsThe following example illustrates how to find content with jQuery text()
and html()
methods:
The following example illustrates how to get the input field value via jQuery val()
:
The jQuery attr()
method is used to find attribute values.
The following example shows how you get the href attribute value in a link:
The next chapter describes how to set (change) content and attribute values.