Text ()
Gets the contents of all matching elements.
The result is text that is combined with the text content contained by all matching elements. This method works for both HTML and XML documents.
Get the text contents to all matched elements.
The result are a string that contains the combined text contents to all matched elements. This method works on both HTML and XML documents.
return value
String
Example
HTML Code:
<p><b>Test</b> paragraph.</p><p>paraparagraph</p>
JQuery Code:
Results:
Test Paragraph.paraparagraph
--------------------------------------------------------------------------------------------- ---------------------------------
text (val)
Set text content for all matching elements
Set the text contents of all matched elements.
Similar to HTML (), but escapes HTML (replace "<" and ">" with their HTML entitie s).
return value
jquery
parameter
Val (String): Text
example
HTML code for setting element content:
<p> ; Test paragraph.</p>
jQuery code:
$ ("P"). Text ( "<b>Some</b> new text.");
result:
[<p><b>Some</b> new text.< ;/p>]
--------------------------------------------------------------------------------------------------------------- ---------------
Val ()
Gets the current value of the first matching element.
In JQuery 1.2, you can return the value of any element. Include SELECT. If multiple selections, an array is returned that contains the selected value.
Get the content of the matched
In JQuery 1.2, a value are now returned for all elements, including selects. For multiple selects an array of values are returned.
return value
String,array
Example
Gets the value of a single select and the value of a multiple select.
HTML Code:
<p></p><br/>
<select id= "single" >
<option>Single</option>
<option>Single2</option>
</select>
<select id= "multiple" multiple= "multiple" >
<option selected= "Selected" >Multiple</option>
<option>Multiple2</option>
<option selected= "Selected" >Multiple3</option>
</select>
JQuery Code:
$ ("P"). Append (
"<b>Single:</b>" + $ ("#single"). Val () +
"<b>Multiple:</b>" + $ ("#multiple"). Val (). Join (",")
);
Results:
[<p><b>single:</b>single<b>multiple:</b>multiple, Multiple3</p>]
Get the value in a text box
HTML Code:
<input type= "text" value= "some text"/>
JQuery Code:
Results:
--------------------------------------------------------------------------------------------------------------- ---------------
Val (Val)
Sets the value of each matching element.
In JQuery 1.2, this can also assign a value to a select component
Set The value attribute of every matched element.
In JQuery 1.2, this is also able to set the value of SELECT elements, but selecting the appropriate options.
return value
Jquery
Parameters
Val (String): The value to set.
Example
Set the value of a text box
HTML Code:
<input type= "Text"/>
JQuery Code:
$ ("input"). val ("Hello world!");
--------------------------------------------------------------------------------------------------------------- ---------------
Val (Val)
Check,select,radio and so on can be used to assign value
return value
Jquery
Parameters
Val (array<string>): Value for Check/select
Example
Sets the value of a select and a multiple selected select
HTML Code:
<select id= "single" >
<option>Single</option>
<option>Single2</option>
</select>
<select id= "multiple" multiple= "multiple" >
<option selected= "Selected" >Multiple</option>
<option>Multiple2</option>
<option selected= "Selected" >Multiple3</option>
</select><br/>
<input type= "checkbox" value= "Check1"/> Check1
<input type= "checkbox" value= "Check2"/> Check2
<input type= "Radio" value= "Radio1"/> Radio1
<input type= "Radio" value= "Radio2"/> Radio2
JQuery Code:
$ ("#single"). Val ("Single2");
$ ("#multiple"). Val (["Multiple2", "Multiple3"]);
$ ("input"). Val (["Check2", "Radio1"]);