HTML, Val, attr, prop differences. This.value and $ (this). Val () Difference and return usage

Source: Internet
Author: User
Tags code tag

HTML ():

The HTML () method returns or sets the contents of the selected element (inner HTML).

When you use this method to read multiple values , it returns the contents of the first matching element.

When you use this method to set a value, it overrides the contents of all matching elements.

When the element content is taken, the code tag below the specified element can be obtained

Text ()

Read multiple return multiple

Similar to HTML (), but only gets the plain text content of the specified element

Val ():

Returns or sets the value of the selected element ( read multiple returns only the first ), which is similar to HTML ()

Set and get by the Value property, commonly used in input elements, only on form elements

attr ():

$ (). attr (property name, property value) →$ (selector). attr (attribute,value)

You can also set multiple $ (selector). attr ({attribute:value, attribute:value ...})

Returns or sets the property value of the selected element property value

A total of four kinds of writing:

attr (property name), gets the first property value if no return undefined

Attr (property name, property value), set so that the property value of the matching element

Attr (property name, function value), setting the function value of the property

attr ({attribute name one: attribute value one, property name two: "Property value Two", ...}), bulk set property value

Prop ()

When the method is used to return a property value, the value of the first matching element is returned.

When the method is used to set property values, one or more property/value pairs are set for the matching element collection.

The four usages are the same as attr.

attr (), the use and difference of prop () :

Attribute/property .attr() .prop()
AccessKey
Align
Async
Autofocus
Checked
Class
Contenteditable
Draggable
Href
Id
Label
Location (i.e. window.location)
Multiple
ReadOnly
Rel
Selected
Src
TabIndex
Title
Type
Width (if needed over .width() )

  

  

Get state representations differently:

attr (' checked '): checked (when unchecked, attr gets undefined)
Prop (' checked '): True (Unity returns true and false)

Add property name immediately in effect with prop;

There are true and false two attributes that can be used with prop;

The intrinsic attributes may be considered using prop;

Other scenarios can be considered using attr, such as custom DOM properties for action processing with attr

  

Value: is the HTML Tag Value property

This.value is the JS original eco-notation, $ (this). Val () is the wording of JQ

Returnreturn control to the page. return False,terminating processingReturn true to continue execution

HTML, Val, attr, prop differences. This.value and $ (this). Val () Difference and return usage

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.