Skip to content

Commit e420da6

Browse files
committed
Events: add note about detaching to all shorthand methods
Fixes gh-717 Closes gh-719
1 parent 424bea3 commit e420da6

24 files changed

Lines changed: 26 additions & 0 deletions

entries/blur.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ $( "#other" ).click(function() {
5252
<p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>
5353
<p>The <code>blur</code> event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the <code>blur</code> event will not work consistently across browsers. As of version 1.4.2, however, jQuery works around this limitation by mapping <code>blur</code> to the <code>focusout</code> event in its event delegation methods, <a href="/live/"><code>.live()</code></a> and <a href="/delegate/"><code>.delegate()</code></a>.</p>
5454
</longdesc>
55+
<note id="detach-shorthand" type="additional" data-event="blur"/>
5556
<example>
5657
<desc>To trigger the blur event on all paragraphs:</desc>
5758
<code><![CDATA[

entries/change.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ $( "#other" ).click(function() {
5656
<p><strong>Note: </strong>Changing the value of an input element using JavaScript, using <a href="/val"><code>.val()</code></a> for example, won't fire the event.</p>
5757
</div>
5858
</longdesc>
59+
<note id="detach-shorthand" type="additional" data-event="change"/>
5960
<example>
6061
<desc>Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw.</desc>
6162
<code><![CDATA[

entries/click.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ $( "#other" ).click(function() {
6161
</ul>
6262
<p>This is usually the desired sequence before taking an action. If this is not required, the <code>mousedown</code> or <code>mouseup</code> event may be more suitable.</p>
6363
</longdesc>
64+
<note id="detach-shorthand" type="additional" data-event="click"/>
6465
<example>
6566
<desc>Hide paragraphs on a page when they are clicked:</desc>
6667
<code><![CDATA[

entries/dblclick.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ $( "#other" ).click(function() {
6464
<p>It is inadvisable to bind handlers to both the <code>click</code> and <code>dblclick</code> events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two <code>click</code> events before the <code>dblclick</code> and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.
6565
</p>
6666
</longdesc>
67+
<note id="detach-shorthand" type="additional" data-event="dblclick"/>
6768
<example>
6869
<desc>To bind a "Hello World!" alert box the dblclick event on every paragraph on the page:</desc>
6970
<code><![CDATA[

entries/error.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $( "#book" )
4343
</div>
4444
<p>Note: A jQuery error event handler should not be attached to the window object. The browser fires the window's error event when a script error occurs. However, the window error event receives different arguments and has different return value requirements than conventional event handlers. Use <code>window.onerror</code> instead.</p>
4545
</longdesc>
46+
<note id="detach-shorthand" type="additional" data-event="error"/>
4647
<example>
4748
<desc>To hide the "broken image" icons for IE users, you can try:</desc>
4849
<code><![CDATA[

entries/focus.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ $( "#other" ).click(function() {
6060
<p>After this code executes, clicks on <samp>Trigger the handler</samp> will also alert the message.</p>
6161
<p>The <code>focus</code> event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the <code>focus</code> event will not work consistently across browsers. As of version 1.4.2, however, jQuery works around this limitation by mapping <code>focus</code> to the <code>focusin</code> event in its event delegation methods, <a href="/live/"><code>.live()</code></a> and <a href="/delegate/"><code>.delegate()</code></a>.</p>
6262
</longdesc>
63+
<note id="detach-shorthand" type="additional" data-event="focus"/>
6364
<example>
6465
<desc>Fire focus.</desc>
6566
<css><![CDATA[

entries/focusin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<p>The <code>focusin</code> event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the <a href="/focus/">focus</a> event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).</p>
2525
<p>This event will likely be used together with the <a href="/focusout/">focusout</a> event.</p>
2626
</longdesc>
27+
<note id="detach-shorthand" type="additional" data-event="focusin"/>
2728
<example>
2829
<desc>Watch for a focus to occur within the paragraphs on the page.</desc>
2930
<css><![CDATA[

entries/focusout.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<p>The <code>focusout</code> event is sent to an element when it, or any element inside of it, loses focus. This is distinct from the <a href="/blur/">blur</a> event in that it supports detecting the loss of focus on descendant elements (in other words, it supports event bubbling).</p>
2525
<p>This event will likely be used together with the <a href="/focusin/">focusin</a> event.</p>
2626
</longdesc>
27+
<note id="detach-shorthand" type="additional" data-event="focusout"/>
2728
<example>
2829
<desc>Watch for a loss of focus to occur inside paragraphs and note the difference between the <code>focusout</code> count and the <code>blur</code> count. (The <code>blur</code> count does not change because those events do not bubble.)</desc>
2930
<css><![CDATA[

entries/keydown.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ $( "#other" ).click(function() {
5454
<p>If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the <code>document</code> object. Because of event bubbling, all key presses will make their way up the DOM to the <code>document</code> object unless explicitly stopped.</p>
5555
<p>To determine which key was pressed, examine the <a href="/category/events/event-object/">event object</a> that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the <code>.which</code> property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows. For catching actual text entry, <code>.keypress()</code> may be a better choice.</p>
5656
</longdesc>
57+
<note id="detach-shorthand" type="additional" data-event="keydown"/>
5758
<example>
5859
<desc>Show the event object for the keydown handler when a key is pressed in the input.</desc>
5960
<code><![CDATA[

entries/keypress.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ $( "#other" ).click(function() {
5959
<p>To determine which character was entered, examine the <code>event</code> object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the <code>.which</code> property so you can reliably use it to retrieve the character code.</p>
6060
<p>Note that <code>keydown</code> and <code>keyup</code> provide a code indicating which key is pressed, while <code>keypress</code> indicates which character was entered. For example, a lowercase "a" will be reported as 65 by <code>keydown</code> and <code>keyup</code>, but as 97 by <code>keypress</code>. An uppercase "A" is reported as 65 by all events. Because of this distinction, when catching special keystrokes such as arrow keys, <code>.keydown()</code> or <code>.keyup()</code> is a better choice.</p>
6161
</longdesc>
62+
<note id="detach-shorthand" type="additional" data-event="keypress"/>
6263
<example>
6364
<desc>Show the event object when a key is pressed in the input. Note: This demo relies on a simple $.print() plugin (http://api.jquery.com/resources/events.js) for the event object's output.</desc>
6465
<code><![CDATA[

0 commit comments

Comments
 (0)