As of jQuery 1.0, the jQuery object (returned by
) has two new read-write attributes:
- html(h)
- val(h)
and one read-only attribute:
- text()
$(expression).html(h)
Description
If the optional h parameter is passed, sets the innerHTML of all elements returned by
to the text of the parameter. If the parameter is not passed, returns the innerHTML of the first element matched by the
.
Examples
$('p').html()
returns the innerHTML of the first <p> element.
$('p').html("inside")
set the innerHTML of all <p> elements to "inside"
$(expression).val(h)
Description
If the optional h parameter is passed, sets the value attribute for all matching elements to the text of the parameter. If the parameter is not passed, returns the value attribute of the first element matched by the expression.
Examples
$('input').val()
returns the value of the first <input> element.
$('input').val("1")
sets the value of all <input> elements to "1".
$(expression).text()
Description
Returns the concatenated text contents of all matching elements.
Examples
$('p').text()
returns the text contents of all <p> elements, concatenated.