Jquery effects, jquery html, jquery traversing, jquery ajax, jquery misc, jquery examples, jquery references, jquery - set content and attributes, set content - text(), html(), and val().
We will use the same three methods from the previous page to set content :
- text() - Sets or returns the text content of selected elements
- html() - Sets or returns the content of selected elements (including HTML markup)
- val() - Sets or returns the value of form fields
The following example demonstrates how to set content with the jQuery text() , html() , and val() methods:
A Callback Function for text(), html(), and val()
All of the three jQuery methods above: text() , html() , and val() , also come with a callback function. The callback function has two parameters: the index of the current element in the list of elements selected and the original (old) value. You then return the string you wish to use as the new value from the function.
The following example demonstrates text() and html() with a callback function:
Set Attributes - attr()
The jQuery attr() method is also used to set/change attribute values.
The following example demonstrates how to change (set) the value of the href attribute in a link:
The attr() method also allows you to set multiple attributes at the same time.
The following example demonstrates how to set both the href and title attributes at the same time:
A Callback Function for attr()
The jQuery method attr() , also comes with a callback function. The callback function has two parameters: the index of the current element in the list of elements selected and the original (old) attribute value. You then return the string you wish to use as the new attribute value from the function.
The following example demonstrates attr() with a callback function:
Test yourself with exercises.
Use a jQuery method to change the text of a <div> element to "Hello World".
Start the Exercise
jQuery HTML Reference
For a complete overview of all jQuery HTML methods, please go to our jQuery HTML/CSS Reference .
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Top references, top examples, get certified.
- API Reference
- Angular Deprecated
- React Deprecated
- Vue Deprecated
- jQuery Deprecated
- Floating Action Button
- Adapt the Size of the Text Area
- Handle the Value Change Event
- Handle the Keyboard Events
- Limit the Text Length
- Data Binding
- Common Features
- Migrate to the New Version
- jQuery Documentation
- UI Components
A newer version of this page is available.
jQuery TextArea - Handle the Value Change Event
When a user types a text into the TextArea, the UI component writes this text into the value property when the change event is raised. If you need this to happen on another event, set the valueChangeEvent property.
To process a new TextArea value, you need to handle the value change event. If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onValueChanged property when you configure the UI component.
If you are going to change event handlers at runtime, or if you need to attach several handlers to the value change event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.
- Handle Events : Angular | Vue | React | jQuery | AngularJS | Knockout
- TextArea - Handle the Keyboard Events
- TextArea Demos
- TextArea API Reference
Attach a function to the change event
Result View the demo in separate window