JQuery (Property manipulation)

Source: Internet
Author: User

1. Manipulate any attribute

A, attr ()

   // 1. Read the Title property of the first Div  console.log ($ ( " div: First   "). attr ( '  title  " ) //  one  // 2. Set the Name property for all Div  (value is Atguigu)  $ ( " div  "  ). attr ( '  name  , "  tom   )   

B, Removeattr ()

// 3. Remove the title attribute of all Div  $ ('div'). Removeattr ('title ' )

C, prop

 //11. Click the ' Select All ' button to select all//attr (): Action property value is not a Boolean value property//prop (): A property that specializes in manipulating property values to Boolean values  var$checkboxs = $ (': CheckBox')  $('Button:first'). Click (function () {$checkboxs. Prop ('checked',true)  })  //12. Click the ' Select All ' button to make all the selections$('Button:last'). Click (function () {$checkboxs. Prop ('checked',false)  })

2. Operation Class Property

A, addclass ()

   // 4. Give all div settings class= ' name '  $ ( " div  Span style= "COLOR: #800000" > ). attr ( "  Class   ", "   Name   " )    5. Add class= ' abc '  $ ( " to all Div Span style= "COLOR: #800000" >div   "). AddClass (  " ABC   )   

B, Removeclass ()

3. Manipulate HTML code, text, value

A, HTML ()

// 7. Get the last Li tag body text  console.log ($ ('li:last'). HTML ())  //  8. Set the first Li's label body as "  $ ('li:first' ). html ('')

B, Val ()

// 9. Get the value in the input box  console.log ($ (': Text'//  read     10. Set the value of the input box to Atguigu  $ (': Text'). Val ('  Value'//  set      read-write Unity

JQuery (Property manipulation)

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.