1. Replacing HTML or text content
Command syntax:html()
Obtains the HTML content of the first element in the matched set.
Parameters
none
Returns
The HTML content of the first matched element. The returned value is identical to accessing the innerHTML property of that element.
Command syntax:html(text)
Sets the passed HTML fragment as the content of all matched elements
Parameters
text (String) The HTML fragment to be set as the element content
Returns
The wrapped set
Command syntax:text()
Concatenates all text content of the wrapped elements and returns it as the result of the command
Parameters
none
Returns
The concatenated string
eg: <ul id="theList">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
// $('#theList').text();//results in variable text being set to OneTwoThreeFour.
Command syntax:text(content)
Sets the text content of all wrapped elements to the passed value. If the passed text contains angle brackets (< and >),
these characters are replaced with their equivalent HTML entities.
Parameters
content (String) The text content to be set into the wrapped elements. Any angle bracket characters are escaped as HTML entities.
Returns
The wrapped set.
Note that setting the inner HTML or text of elements using these commands will replace contents that were previously in the elements.
2.Moving and copying elements
Command syntax:append(content)
Appends the passed HTML fragment or elements to the content in all matched elements.
Parameters
content (String|Element|Object) A string, element, or wrapped set to append to the elements of the wrapped set.
Returns
The wrapped set.
Command syntax:appendTo(target)
Moves all elements in the wrapped set to the end of the content of the specified target(s).
Parameters
target (String|Element) A string containing a jQuery selector or a DOM element. Each element of the wrapped set will be appended to that location.
If more than one element matches a string selector, the element will be copied and appended to each element matching the selector.
Returns
The wrapped set.
A number of related commands work in a fashion similar to append() and appendTo():
■ prepend() and prependTo()—Work like append() and appendTo(), but insert the source element before the destination target’s contents instead of after.
These commands can also be demonstrated in the Move and Copy Laboratory by clicking the PrependTo radio button before clicking Execute.
■ before() and insertBefore()—Insert the element before the destination elements instead of before the destination’s first child.
■ after() and insertAfter()—Insert the element after the destination elements instead of after the destination’s last child.
eg: $('<p>Hi there!</p>').insertAfter('p img');//This statement creates a friendly paragraph and inserts a copy of it after every image element within a paragraph element.
3. Wrapping elements
Command syntax:wrap(wrapper)
Wraps the elements of the matched set with the passed HTML tags or a clone of the passed element.
Parameters
wrapper (String|Element) The opening and closing tags of the element with which to wrap each element of the matched set, or an element to be cloned and server
as the wrapper.
Returns
The wrapped set.
eg: $("a.surprise").wrap("<div class='hello'></div>") //Wrap each link with the class surprise in a <div> with the class hello
Command syntax:wrapAll(wrapper)
Wraps the elements of the matched set, as a unit, with the passed HTML tags or a clone of the passed element.
Parameters
wrapper (String|Element) The opening and closing tags of the element with which to wrap each element of the matched set, or an element to be cloned and server as the wrapper.
Returns
The wrapped set
Command syntax:wrapInner(wrapper)
Wraps the contents, to include text nodes , elements of the matched set with the passed HTML tags or a clone of the passed element.
Parameters
wrapper (String|Element) The opening and closing tags of the element with which to wrap each element of the matched set, or an element to be cloned and server as the wrapper.
Returns
The wrapped set
4.Removing elements
Command syntax:remove()
Removes all elements in the wrapped set from the page DOM
Parameters
none
Returns
The wrapped set
Command syntax:empty()
Removes the content of all DOM elements in the matched set
Parameters
none
Returns
The wrapped set
5. Cloning elements
Command syntax:clone(copyHandlers)
Creates copies of the elements in the wrapped set and returns a new wrapped set that contains them. The elements and any children are copied.
Event handlers are optionally copied depending upon the setting of the copyHandlers parameter.
Parameters
copyHandlers (Boolean) If true, event handlers are copied. If false, or omitted, handlers are not copied.
Returns
The newly created wrapped set.
6. Dealing with form element values
Command syntax:val()
Returns the value property of the first element in the matched set. When the element is a multi-select element, the returned value is an array of all selections.
Parameters
none
Returns
The fetched value or values.
eg: $('[name=radioGroup]:checked').val()//returns the value of the single checked radio button (or undefined if none is checked).
Command syntax:val(value)
Sets the passed value as the value of all matched form elements
Parameters
value (String) A string that’s set as the value property of each form element in the wrapped set
Returns
The wrapped set
Command syntax:val(values)
Causes any check boxes, radio buttons, or options of <select> elements in the wrapped set to become checked
or selected if their values match any of the values passed in the values array.
Parameters
values (Array) An array of values that will be used to determine which elements are to be checked or selected.
Returns
The wrapped set.
eg: $('input,select').val(['one','two','three']);//This statement will search all the <input> and <select> elements on the page for
values that match any of the input strings: one, two or three. Any check boxes or
radio buttons that are found to match will become checked, and any options that
match will become selected.
分享到:
相关推荐
- **`activate(element)`**: Activates an element, typically by setting focus or enabling it. - **`clear(element)`**: Clears the value of an element. - **`disable(element)`**: Disables an element, ...
- FIX: Label "Max Lines" setting now works correctly with the "Shrink Content" overflow setting. - FIX: Draggable panel now uses whole numbers, keeping itself pixel-perfect. - FIX: UIPlayAnimation ...
cursor: 'pointer', // cursor css setting for side bar areas hash: false, // enables navigation using a hash string, ex: #/page/1 for page 1, will affect all booklets with 'hash' enabled keyboard: ...
This is achieved by setting the `contenteditable` attribute on HTML elements. ```html <p contenteditable="true">This text can be edited. ``` #### Messaging API The Messaging API includes ...
1. 如果收到“Received content of invalid Content-Type setting:text/html - SOAP expects 'text/xml'”错误,这通常是因为Content-Type不正确。解决方法是调整ISAPIApp和ISAPIThreadPool的加载顺序。 2. “XML ...
It blends together rich content from a wide range of sources and allows you unparalleled access to the processing power of your Windows computer. Pro WPF 4.5 in C# provides a thorough, ...
This technology, when combined with JavaScript, CSS3, and WebGL, allows for the creation of rich, dynamic content that was previously only possible with plugins like Flash. In this detailed overview,...
"profile.default_content_setting_values.notifications": 2 } chrome_options.add_experimental_option("prefs", prefs) # 根据需求设置 Chrome 启动参数 if chrome_args().get("headless_flag") == "1": ...
Organizing content into pages (pagination) 185 Summary 190 Chapter 10: Building User Networks 191 Building friend networks 191 Creating the friendship data model 192 Writing views to manage ...
You can also insert Form elements (checkbox, button, textarea, etc.) and modify certain properties of the element. 默认换行为软回车 (Demo) <br/>Most other editors insert double line ...
$(element).zTree(setting); } }; }); ``` 在`setting`对象中可以详细配置zTree的各种属性,以实现特定的功能需求。通过AngularJS的`ng-model`绑定到`selectNode`,可以将当前选中的节点同步到应用的其他部分。 ...
15.5 Element Content 378 15.6 Creating, Inserting, and Deleting Nodes 382 15.7 Example: Generating a Table of Contents 387 15.8 Document and Element Geometry and Scrolling 389 15.9 HTML Forms 396 ...
Setting it to TRUE forces exporting editor's text in ANSI format. CBCGPRibbonStatusBarPane constructor and SetAnimationList method have a new optional parameter 'BOOL bDontScaleInHighDPIMode'. Set ...
Updated module: ElementTree 1.3 Build and C API Changes Capsules Port-Specific Changes: Windows Port-Specific Changes: Mac OS X Port-Specific Changes: FreeBSD Other Changes and Fixes Porting to ...
Restricting Attribute Setting Recipe 6.4. Chaining Dictionary Lookups Recipe 6.5. Delegating Automatically as an Alternative to Inheritance Recipe 6.6. Delegating Special Methods in Proxies ...
Contents Page 0 Introduction.................................................................................................................................................................