First, get the page element
Three ways to get the contents of an element in a page.
The input tag uses:. val () to get
HTML and text content under Tags:. html ()
Get only plain text content under Tags:. Text ()
<Head> <Scripttype= "Text/javascript"> $(function() {Console.log ($ (". 1"). HTML ());//gets all the values that contain HTML <p>a</p>Console.log ($ (". 2"). text ());//get text content only, don't get HTML tags }); </Script> </Head> <Body> <Div> <ul> <Liclass= "1"><P>A</P></Li> <Liclass= "2"><P>B</P></Li> </ul> </Div> </Body>
Second, edit page elements
. HTML (htmlstring),. Text (TextString), and. Val (value) Three methods are used to replace the contents of the selected element, and if three methods are applied on more than one element at the same time, the contents of all the selected elements will be replaced.
jquery get tag content, edit content