Skip to content

Commit 15c9c63

Browse files
committed
ID selector: clarify returned # of elements.
Fixes #11
1 parent 221e0f6 commit 15c9c63

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

entries/id-selector.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<desc>Selects a single element with the given id attribute. </desc>
1212
<longdesc>
1313
<p>For id selectors, jQuery uses the JavaScript function <code>document.getElementById()</code>, which is extremely efficient. When another selector is attached to the id selector, such as <code>h2#pageTitle</code>, jQuery performs an additional check before identifying the element as a match.</p>
14-
<blockquote>
15-
<p>As always, remember that as a developer, your time is typically the most valuable resource. Do not focus on optimization of selector speed unless it is clear that performance needs to be improved.</p>
16-
</blockquote>
14+
<p>Calling <code>jQuery()</code> (or <code>$()</code>) with an id selector as its argument will return a jQuery object containing a collection of either zero or one DOM element.</p>
1715
<p>Each <code>id</code> value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid.</p>
1816
<p>If the id contains characters like periods or colons you have to <a href="http://learn.jquery.com/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/">escape those characters with backslashes</a>.</p>
1917
</longdesc>
2018
<example>
21-
<desc>Finds the element with the id "myDiv".</desc>
22-
<code><![CDATA[$("#myDiv").css("border","3px solid red");]]></code>
19+
<desc>Select the element with the id "myDiv" and give it a red border.</desc>
20+
<code><![CDATA[
21+
$( "#myDiv" ).css( "border","3px solid red" );
22+
]]></code>
2323
<html><![CDATA[<div id="notMe"><p>id="notMe"</p></div>
2424
2525
<div id="myDiv">id="myDiv"</div>]]></html>
@@ -35,8 +35,10 @@
3535
]]></css>
3636
</example>
3737
<example>
38-
<desc>Finds the element with the id "myID.entry[1]". See how certain characters must be escaped with backslashes.</desc>
39-
<code><![CDATA[$("#myID\\.entry\\[1\\]").css("border","3px solid red");]]></code>
38+
<desc>Select the element with the id "myID.entry[1]" and give it a red border. Note how certain characters must be escaped with backslashes.</desc>
39+
<code><![CDATA[
40+
$( "#myID\\.entry\\[1\\]" ).css( "border", "3px solid red" );
41+
]]></code>
4042
<html><![CDATA[<div id="myID.entry[0]">id="myID.entry[0]"</div>
4143
4244
<div id="myID.entry[1]">id="myID.entry[1]"</div>

0 commit comments

Comments
 (0)