codeGK
Code it ALL
jQuery Set - CodeGK
♦ jQuery Set

♣ About jQuery Set

jQuery set() method gives a way to set data for HTML elements of particular type.
There are broadly four categories of data set methods, namely text(text_data), html(html_data), val(val_data) and attr(attribute_data).
Note that the parameter is the data value to be set to the respective types.

♣ Example1: jQuery set html()

Sets the HTML content of selected HTML element, i.e, the input will have tags along with text.
Basic Syntax
$(selector).html(html_data);
selector: the HTML element to be selected
html(): syntax for assigning text with html tags.
html_data: content, including HTML tags.
In this example, jQuery set html() method is illustrated.
Example
Input:
Output:

♣ Example2: jQuery set text()

Sets the Textual content of selected HTML element, i.e, the input will only be having text and the tags are not supposed to be there.
Basic Syntax
$(selector).text("text_data");
selector: the HTML element to be selected
text(): syntax for assigning text without html tags.
text_data: textual content, excluding HTML tags.
In this example, jQuery set text() method is illustrated.
Example
Input:
Output:

♣ Example3: jQuery set val()

Sets the Value content of selected HTML element for the form.
Basic Syntax
$(selector).val("val_data");
selector: the HTML element to be selected
val(): syntax for assigning value(ghost value) to form.
val_data: content for value of input.
In this example, jQuery set val() method is illustrated.
Example
Input:
Output:

♣ Example4: jQuery set attr()

Sets the Attribute content of selected HTML element from selected attribute.
Basic Syntax
$(selector).attr("attribute_data");
selector: the HTML element to be selected
attr(): syntax for assigning value to attribute of selected HTML element.
attribute_data: content for href of HTML tag.
In this example, jQuery set attr() method is illustrated.
Example
Input:
Output:
Prev_LessonNext_Lesson