jquery attribute Operation attr () Val () HTML ()

Source: Internet
Author: User


1:attr () Sets or returns the property value


alert ("Image width" + $ ("img"). attr ("width"));returns the attribute value of an element

  $ ("img").attr("width","180"); Set the attribute value of an element

$ ("img"). attr ({width: "", "Height:"}); setting multiple Property values
$ ("P"). Removeattr ("style"); Remove the style Property of the P tag <p style= "font-size:120%;color:red" > This is a paragraph. </p>

2:html ():Sets or returns the HTML value of an element

$ ("P"). html("Hello <b>world</b>!")  Set the contents of the P element

Alert ($ ("P"). html ()); Returns the element content of the P tag

3:val () general settings for the value of the INPUT element

$ (": Text"). val("Hello World") ; Set the value of a text field

Alert ($ ("Input:text"). Val ()); Returns the value of a text field

jquery attribute Operation attr () Val () HTML ()

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.