mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-18 15:00:23 +00:00
Inset listviews have no margin now, and regular listviews have -15px margins. Also, collapsibles now have no padding. Updated HTML to remove ui-body classes for content divs, to match these changes. Fixes #161
132 lines
No EOL
5.7 KiB
HTML
132 lines
No EOL
5.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang='en'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
|
|
<div data-role="page">
|
|
<div data-role="header">
|
|
<h1>.end()</h1>
|
|
|
|
</div>
|
|
<div data-role="content" data-theme="c" id="end1">
|
|
<h2 class="jq-clearfix roundTop section-title">
|
|
<span class="name">.end()</span> <span class="returns">Returns: <a class="return" href="http://docs.jquery.com/Types#jQuery">jQuery</a></span>
|
|
</h2>
|
|
<div class=" entry-details">
|
|
<p class="desc"><strong>Description: </strong>End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.</p>
|
|
<ul class="signatures"><li class="signature" id="end"><h4 class="name">
|
|
<span class="versionAdded">version added: <a href="/category/version/1.0/">1.0</a></span>.end()</h4></li></ul>
|
|
<div class="longdesc">
|
|
<p>Most of the methods in this chapter operate on a jQuery object and produce a new one, matching a different set of DOM elements. When this happens, it is as if the new set of elements is pushed onto a stack that is maintained inside the object. Each successive filtering method pushes a new element set onto the stack. If we need an older element set, we can use <code>end()</code> to pop the sets back off of the stack.</p>
|
|
<p>Suppose we have a couple short lists on a page:</p>
|
|
<pre>
|
|
<ul class="first">
|
|
<li class="foo">list item 1</li>
|
|
<li>list item 2</li>
|
|
<li class="bar">list item 3</li>
|
|
</ul>
|
|
<ul class="second">
|
|
<li class="foo">list item 1</li>
|
|
<li>list item 2</li>
|
|
<li class="bar">list item 3</li>
|
|
</ul>
|
|
</pre>
|
|
<p>The <code>end()</code> method is useful primarily when exploiting jQuery's chaining properties. When not using chaining, we can usually just call up a previous object by variable name, so we don't need to manipulate the stack. With <code>end()</code>, though, we can string all the method calls together:</p>
|
|
<pre>
|
|
$('ul.first').find('.foo').css('background-color', 'red')
|
|
<code>.end()</code>.find('.bar').css('background-color', 'green');
|
|
</pre>
|
|
<p>This chain searches for items with the class <code>foo</code> within the first list only and turns their backgrounds red. Then <code>end()</code> returns the object to its state before the call to <code>find()</code>, so the second <code>find()</code> looks for '.bar' inside <code><ul class="first"></code>, not just inside that list's <code><li class="foo"></code>, and turns the matching elements' backgrounds green. The net result is that items 1 and 3 of the first list have a colored background, and none of the items from the second list do.</p>
|
|
<p>A long jQuery chain can be visualized as a structured code block, with filtering methods providing the openings of nested blocks and <code>end()</code> methods closing them:</p>
|
|
<pre>
|
|
$('ul.first').find('.foo')
|
|
.css('background-color', 'red')
|
|
.end().find('.bar')
|
|
.css('background-color', 'green')
|
|
.end();
|
|
</pre>
|
|
<p>The last <code>end()</code> is unnecessary, as we are discarding the jQuery object immediately thereafter. However, when the code is written in this form, the <code>end()</code> provides visual symmetry and closure—making the program, at least to the eyes of some developers, more readable.</p>
|
|
</div>
|
|
<h3>Examples:</h3>
|
|
<div id="entry-examples" class="entry-examples">
|
|
<div id="example-0">
|
|
<h4>Example: <span class="desc">Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs.</span>
|
|
</h4>
|
|
<pre><code class="example demo-code"><!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>
|
|
p, div { margin:1px; padding:1px; font-weight:bold;
|
|
font-size:16px; }
|
|
div { color:blue; }
|
|
b { color:red; }
|
|
</style>
|
|
<script src="http://code.jquery.com/jquery-latest.js"></script>
|
|
</head>
|
|
<body>
|
|
<p>
|
|
Hi there <span>how</span> are you <span>doing</span>?
|
|
</p>
|
|
|
|
<p>
|
|
This <span>span</span> is one of
|
|
several <span>spans</span> in this
|
|
<span>sentence</span>.
|
|
</p>
|
|
|
|
<div>
|
|
Tags in jQuery object initially: <b></b>
|
|
</div>
|
|
<div>
|
|
Tags in jQuery object after find: <b></b>
|
|
|
|
</div>
|
|
<div>
|
|
Tags in jQuery object after end: <b></b>
|
|
</div>
|
|
<script>
|
|
|
|
jQuery.fn.showTags = function (n) {
|
|
var tags = this.map(function () {
|
|
return this.tagName;
|
|
})
|
|
.get().join(", ");
|
|
$("b:eq(" + n + ")").text(tags);
|
|
return this;
|
|
};
|
|
|
|
$("p").showTags(0)
|
|
.find("span")
|
|
.showTags(1)
|
|
.css("background", "yellow")
|
|
.end()
|
|
.showTags(2)
|
|
.css("font-style", "italic");
|
|
|
|
</script>
|
|
</body>
|
|
</html></code></pre>
|
|
<h4>Demo:</h4>
|
|
<div class="demo code-demo"></div>
|
|
</div>
|
|
<div id="example-1">
|
|
<h4>Example: <span class="desc">Selects all paragraphs, finds span elements inside these, and reverts the selection back to the paragraphs.</span>
|
|
</h4>
|
|
<pre><code class="example demo-code"><!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>p { margin:10px; padding:10px; }</style>
|
|
<script src="http://code.jquery.com/jquery-latest.js"></script>
|
|
</head>
|
|
<body>
|
|
<p><span>Hello</span>, how are you?</p>
|
|
<script>$("p").find("span").end().css("border", "2px red solid");</script>
|
|
</body>
|
|
</html></code></pre>
|
|
<h4>Demo:</h4>
|
|
<div class="demo code-demo"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body></html> |