Skip to content

Commit c942ea5

Browse files
committed
Merge branch 'master' into jquery-1.9
* master: Add entry for $.parseHTML Add deprecation notices for error load, unload events Add entry for jQuery.parseHTML() :checked selector: Clean up examples .addClass(): Trivial cleanup. jQuery.contains(): Clarify language. Mark .toggle() event as deprecated in 1.8 Removing <em> tags from example code on live() entry - Closes jquerygh-165
2 parents db98c25 + 0056ce6 commit c942ea5

File tree

9 files changed

+87
-29
lines changed

9 files changed

+87
-29
lines changed

entries/addClass.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
<p>Given an unordered list with five <code>&lt;li&gt;</code> elements, this example adds the class "item-4" to the last <code>&lt;li&gt;</code>.</p>
2929
</longdesc>
3030
<example>
31-
<desc>Adds the class "selected" to the matched elements.</desc>
31+
<desc>Add the class "selected" to the matched elements.</desc>
3232
<code><![CDATA[
33-
$("p:last").addClass("selected");
33+
$("p").last().addClass("selected");
3434
]]></code>
3535
<css><![CDATA[
3636
p { margin: 8px; font-size:16px; }
@@ -44,7 +44,7 @@
4444
]]></html>
4545
</example>
4646
<example>
47-
<desc>Adds the classes "selected" and "highlight" to the matched elements.</desc>
47+
<desc>Add the classes "selected" and "highlight" to the matched elements.</desc>
4848
<code><![CDATA[
4949
$("p:last").addClass("selected highlight");
5050
]]></code>
@@ -67,7 +67,7 @@
6767
addedClass = "green";
6868
$("p").text("There is one green div");
6969
}
70-
70+
7171
return addedClass;
7272
});
7373
]]></code>
@@ -89,4 +89,4 @@
8989
<category slug="css"/>
9090
<category slug="version/1.0"/>
9191
<category slug="version/1.4"/>
92-
</entry>
92+
</entry>

entries/checked-selector.xml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,39 @@
1010
<p>The <code>:checked</code> selector works for checkboxes and radio buttons. For select elements, use the <code>:selected</code> selector.</p>
1111
</longdesc>
1212
<example>
13-
<desc>Finds all input elements that are checked.</desc>
13+
<desc>Determine how many input elements are checked.</desc>
1414
<code><![CDATA[
15-
function countChecked() {
16-
var n = $("input:checked").length;
17-
$("div").text(n + (n === 1 ? " is" : " are") + " checked!");
18-
}
15+
var countChecked = function() {
16+
var n = $( "input:checked" ).length;
17+
$( "div" ).text( n + (n === 1 ? " is" : " are") + " checked!" );
18+
};
1919
countChecked();
20-
$(":checkbox").click(countChecked);
20+
21+
$( "input[type=checkbox]" ).on( "click", countChecked );
2122
]]></code>
2223
<css><![CDATA[
2324
div { color:red; }
2425
]]></css>
2526
<html><![CDATA[
2627
<form>
2728
<p>
28-
<input type="checkbox" name="newsletter" checked="checked" value="Hourly" />
29+
<input type="checkbox" name="newsletter" value="Hourly" checked="checked">
2930
30-
<input type="checkbox" name="newsletter" value="Daily" />
31-
<input type="checkbox" name="newsletter" value="Weekly" />
31+
<input type="checkbox" name="newsletter" value="Daily">
32+
<input type="checkbox" name="newsletter" value="Weekly">
3233
33-
<input type="checkbox" name="newsletter" checked="checked" value="Monthly" />
34-
<input type="checkbox" name="newsletter" value="Yearly" />
34+
<input type="checkbox" name="newsletter" value="Monthly" checked>
35+
<input type="checkbox" name="newsletter" value="Yearly">
3536
</p>
3637
</form>
3738
<div></div>
3839
]]></html>
3940
</example>
4041
<example>
42+
<desc>Identify the checked radio input.</desc>
4143
<code><![CDATA[
42-
$("input").click(function() {
43-
$("#log").html( $(":checked").val() + " is checked!" );
44+
$( "input" ).on( "click", function() {
45+
$( "#log" ).html( $("input:checked").val() + " is checked!" );
4446
});
4547
]]></code>
4648
<css><![CDATA[
@@ -66,4 +68,4 @@ input, label { line-height: 1.5em; }
6668
</example>
6769
<category slug="selectors/form-selectors"/>
6870
<category slug="version/1.0"/>
69-
</entry>
71+
</entry>

entries/error.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0"?>
22
<entry type="method" name="error" return="jQuery">
33
<title>.error()</title>
4+
<deprecated>1.8</deprecated>
45
<desc>Bind an event handler to the "error" JavaScript event.</desc>
56
<signature>
67
<added>1.0</added>

entries/jQuery.contains.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
<desc>The DOM element that may contain the other element.</desc>
88
</argument>
99
<argument name="contained" type="Element">
10-
<desc>The DOM element that may be contained by the other element.</desc>
10+
<desc>The DOM element that may be contained by (a descendant of) the other element.</desc>
1111
</argument>
1212
</signature>
13-
<desc>Check to see if a DOM element is within another DOM element.</desc>
13+
<desc>Check to see if a DOM element is a descendant of another DOM element.</desc>
1414
<longdesc>
15+
<p>The <code>$.contains()</code> method returns <code>true</code> if the DOM element provided by the second argument is a descendant of the DOM element provided by the first argument, whether it is a direct child or nested more deeply. Otherwise, it returns <code>false</code>. Only <em>element</em> nodes are supported; if the second argument is a text or comment node, <code>$.contains()</code> will return <code>false</code>.</p>
1516
<blockquote>
1617
<p><strong>Note:</strong> The first argument <em>must</em> be a DOM element, not a jQuery object or plain JavaScript object.</p>
1718
</blockquote>
1819
</longdesc>
1920
<example>
20-
<desc>Check if an element is inside another. Text and comment nodes are not supported.</desc>
21-
<code><![CDATA[jQuery.contains(document.documentElement, document.body); // true
22-
jQuery.contains(document.body, document.documentElement); // false]]></code>
21+
<desc>Check if an element is a descendant of another.</desc>
22+
<code><![CDATA[$.contains( document.documentElement, document.body ); // true
23+
$.contains( document.body, document.documentElement ); // false]]></code>
2324
</example>
2425
<category slug="utilities"/>
2526
<category slug="version/1.4"/>
26-
</entry>
27+
</entry>

entries/jQuery.parseHTML.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0"?>
2+
<entry type="method" name="jQuery.parseHTML" return="Array">
3+
<title>jQuery.parseHTML()</title>
4+
<desc>Parses a string into an array of DOM nodes.</desc>
5+
<signature>
6+
<added>1.8</added>
7+
<argument name="data" type="String">
8+
<desc>HTML string to be parsed</desc>
9+
</argument>
10+
<argument name="context" type="Element" optional="true" default="document">
11+
<desc>DOM element to serve as the context in which the HTML fragment will be created</desc>
12+
</argument>
13+
<argument name="keepScripts" type="Boolean" optional="true" default="false">
14+
<desc>A Boolean indicating whether to include scripts passed in the HTML string</desc>
15+
</argument>
16+
</signature>
17+
<longdesc>
18+
<p><code>jQuery.parseHTML</code> uses a native DOM element creation function to convert the string to a set of DOM elements, which can then be inserted into the document.</p>
19+
</longdesc>
20+
<example>
21+
<desc>Create an array of Dom nodes using an HTML string and insert it into a div.</desc>
22+
<html><![CDATA[
23+
<div id="log">
24+
<h3>Content:</h3>
25+
</div>
26+
]]></html>
27+
<code><![CDATA[
28+
var $log = $( "#log" ),
29+
str = "hello, <b>my name is</b> jQuery.",
30+
html = $.parseHTML( str ),
31+
nodeNames = [];
32+
33+
// Append the parsed HTML
34+
$log.append( html );
35+
36+
// Gather the parsed HTML's node names
37+
$.each( html, function( i, el ) {
38+
nodeNames[i] = "<li>" + el.nodeName + "</li>";
39+
});
40+
41+
// Insert the node names
42+
$log.append( "<h3>Node Names:</h3>" );
43+
$( "<ol></ol>" )
44+
.append( nodeNames.join( "" ) )
45+
.appendTo( $log );
46+
47+
]]></code>
48+
</example>
49+
<category slug="utilities"/>
50+
<category slug="version/1.8"/>
51+
</entry>

entries/live.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
<p>This method provides a means to attach delegated event handlers to the <code>document</code> element of a page, which simplifies the use of event handlers when content is dynamically added to a page. See the discussion of direct versus delegated events in the <a href="http://api.jquery.com/on/"><code>.on()</code></a> method for more information. </p>
3535
<p>Rewriting the <code>.live()</code> method in terms of its successors is straightforward; these are templates for equivalent calls for all three event attachment methods:</p>
3636
<pre><code>
37-
$(<em>selector</em>).live(<em>events</em>, <em>data</em>, <em>handler</em>); // jQuery 1.3+
38-
$(document).delegate(<em>selector</em>, <em>events</em>, <em>data</em>, <em>handler</em>); // jQuery 1.4.3+
39-
$(document).on(<em>events</em>, <em>selector</em>, <em>data</em>, <em>handler</em>); // jQuery 1.7+
37+
$(selector).live(events, data, handler); // jQuery 1.3+
38+
$(document).delegate(selector, events, data, handler); // jQuery 1.4.3+
39+
$(document).on(events, selector, data, handler); // jQuery 1.7+
4040
</code></pre>
4141
<p>The <code>events</code> argument can either be a space-separated list of event type names and optional namespaces, or an object of event name strings and handlers. The <code>data</code> argument is optional and can be omitted. For example, the following three method calls are functionally equivalent (but see below for more effective and performant ways to attach delegated event handlers):</p>
4242
<pre><code>

entries/load-event.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0"?>
22
<entry type="method" name="load" return="jQuery">
33
<title>.load()</title>
4+
<deprecated>1.8</deprecated>
45
<desc>Bind an event handler to the "load" JavaScript event.</desc>
56
<signature>
67
<added>1.0</added>

entries/toggle-event.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0"?>
22
<entry type="method" name="toggle" return="jQuery">
33
<title>.toggle()</title>
4+
<deprecated>1.8</deprecated>
45
<desc>Bind two or more handlers to the matched elements, to be executed on alternate clicks.</desc>
56
<signature>
67
<added>1.0</added>
@@ -85,4 +86,4 @@
8586
</example>
8687
<category slug="events/mouse-events"/>
8788
<category slug="version/1.0"/>
88-
</entry>
89+
</entry>

entries/unload.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0"?>
22
<entry type="method" name="unload" return="jQuery">
33
<title>.unload()</title>
4+
<deprecated>1.8</deprecated>
45
<signature>
56
<added>1.0</added>
67
<argument name="handler(eventObject)" type="Function">

0 commit comments

Comments
 (0)