1. Access to Content
Three simple and practical jQuery methods for DOM manipulation:
- Text ()-Sets or returns the text content of the selected element
- HTML ()-Sets or returns the contents of the selected element (including HTML tags)
- Val ()-Sets or returns the value of a form field
<PID= "Test">This is some<b>Bold</b>text in a paragraph.</P><P>Name:<inputtype= "text"ID= "Test2"value= "Mickey Mouse"></P>
$ ("#test"). Text ()------This was some bold text in a paragraph.
$ ("#test"). HTML ()-----This was some <b>bold</b> text in a paragraph.
$ ("#test2"). Val ()------Mickey Mouse
2. Get Properties
The JQuery attr () method is used to get the property value
< P >< href= "http://www.w3cschool.cc" ID= "w3s">w3cschool.cc </ a ></ P >
$ ("#w3s"). attr ("href")------http://www.w3cschool.cc
3. Setting content and properties
or the text, HTML, Val, attr above.
attr set multiple properties at the same time:
$ ("#w3s"). attr ({ "href": "Http://www.w3cschool.cc/jquery", "title": "W3Schools jquery Tutorial"});
The difference between 4.attr and prop
Compared to the Attr,prop is 1.6.1 only new, both from the Chinese meaning understanding, are to get/set the property of the method (attributes and properties). Only the. attr () method used in window or document does not work properly before jQuery1.6 because the window and document cannot have attributes. Prop was born.
Reference: http://www.javascript100.com/?p=877
It is obviously better to use the Prop method when encountering properties to get or set checked,selected,readonly and disabled
The attr method inside, the most critical of the two lines of code, Elem.setattribute (name, Value + "") and ret = Elem.getattribute (name), is clearly seen, using the DOM API The SetAttribute and GetAttribute methods manipulate the property element nodes .
And the prop method inside, the most critical two lines of code, return (elem[name] = value) and return elem[name], you can understand so document.getElementById (EL) [Name] = value, which is a property that translates into a JS object.
jquery Note Three--text/html/val/attr/prop