Js uses the html () or text () method to obtain the value displayed for setting the p tag, jstext
Html () method
This method is similar to the innerHTML attribute in JavaScript and can be used to read or set the HTML content in an element. To obtain the content of an element, you can:
Var p_html = $ ("p" ).html (); // obtain the HTML code of the p element
If you need to set the HTML code of an element, you can also use this method, but you need to pass a parameter for it. For example, to set the HTML code of the p element, you can use the following code:
// Set the HTML code for the p element $ ("p" ).html ("welcome to the concise modern magic library ~~ ");
Note: The html () method can be used for XHTML documents, but not for XML documents.
Text () method
This method is similar to the innerText attribute in JavaScript. It can be used to read or leave the text content in an element empty. Continue to use the preceding HTML code and use the text () method to operate the p element:
Var p_text = $ ("p"). text (); // obtain the text content of the p element.
Like the html () method, if you need to set text content for an element, you also need to pass a parameter. For example, to set text content for the p element, the Code is as follows:
// Set the text content of the p element $ ("p"). text ("welcome to the concise modern magic library ~~ ");
Pay attention to the following two points:
The innerText attribute in JavaScript cannot be run in the Firefox browser, while jQuery's text () method supports all browsers.
The text () method is effective for both HTML and XML documents.
When the friend list is displayed, set <p id = "p $ {friend. friendId} "> </p>. In this way, the id of the <p> </p> element can be dynamically obtained in the js file () method value $ ("# p" + userId ). text (name );
How can I use js to retrieve the value of the html: text box?
Assume that the property value of the html: text label is abc, so the following can be written in js:
Document. forms [0]. abc. value
How to Use JS to get content in HTML tags
I don't know where I am
<Body>
<P id = "ss"> content </p> <input type = "button" name = "Submit" value = "show" onclick = "s ()"/>
</Body>
<Script>
Function s ()
{
Alert (document. getElementById ("ss"). innerHTML );
}
</Script>