jquery get tag content, edit content

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.