jQuery  getter and setter methods

jQuery - Get and Set Methods

jQuery get and set methods provide different getter method such as text (),html (),attr () and val ().These methods are used to get(or read) the value of the element.

Please keep in mind that jquery getter methods do not take any argument.

Different Between Getters And Setters Method

Getter's method does not take an argument, because it takes(or reads) the value from the element while the setter methods take argument since it assigns (or sets) value to the element.

jQuery text() method

jQuery text() method is used to get or set textual content to the selected elements.

Please keep in mind that the jQuery getter text() method is used to retrieve the values ??of all selected elements while other getter methods(html (), attr () and val ()) return only the value of the first selected element.

General Syntax

Try it now

Source Code

Try it now

Setting Of Textual Content With text() Method

Let us see the setter text() method example.

General Syntax

Try it now

Source Code

Try it now

jQuery html() Method

Jquery HTML() method is used as a getter(read the data) and setter(set the data) for the selected HTML element. Basically, It gets or sets the HTML content of the selected element.

General Syntax

Try it now

Source Code

Try it now

Set The Content Using jQuery html() Method

General Syntax

Try it now

Source Code

Try it now

jQuery attr() Method

The primary aim of using the jquery attr() method is to get the selected element attribute's value or set one or more attributes to the selected element.

Fetching Attribute Value Using jQuery attr() Method

General Syntax

Try it now

Source Code

Try it now

Set Attributes with attr() Method

General Syntax

Try it now

Source Code

Try it now

jQuery val() Method

It is mainly used to set or get the current value of HTML form elements. These form elements are <input>, <select> and <textarea>.

Fetching The Form Field Value Using val() Method

General Syntax

Try it now

Source Code

Try it now