Skip to content

Commit 7425781

Browse files
committed
Merge pull request jquery#40 from kborchers/master
Add <code> tags inside all <pre> tags that contain code examples
2 parents 6e1aef9 + e3addc0 commit 7425781

File tree

137 files changed

+831
-828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+831
-828
lines changed

entries/addClass.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
<longdesc>
1818
<p>It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.</p>
1919
<p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>
20-
<pre>$("p").addClass("myClass yourClass");</pre>
20+
<pre><code>$("p").addClass("myClass yourClass");</code></pre>
2121
<p>This method is often used with <code>.removeClass()</code> to switch elements' classes from one to another, like so:</p>
22-
<pre>$("p").removeClass("myClass noClass").addClass("yourClass");</pre>
22+
<pre><code>$("p").removeClass("myClass noClass").addClass("yourClass");</code></pre>
2323
<p>Here, the <code>myClass</code> and <code>noClass</code> classes are removed from all paragraphs, while <code>yourClass</code> is added.</p>
2424
<p>As of jQuery 1.4, the <code>.addClass()</code> method's argument can receive a function.</p>
25-
<pre>$("ul li:last").addClass(function(index) {
25+
<pre><code>$("ul li:last").addClass(function(index) {
2626
return "item-" + index;
27-
});</pre>
27+
});</code></pre>
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>

entries/after.xml

+17-17
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,58 @@
2020
<longdesc>
2121
<p>The <code>.after()</code> and <code><a href="/insertAfter">.insertAfter()</a></code> methods perform the same task. The major difference is in the syntax&#x2014;specifically, in the placement of the content and target. With<code> .after()</code>, the selector expression preceding the method is the container after which the content is inserted. With <code>.insertAfter()</code>, on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted after the target container.</p>
2222
<p>Using the following HTML:</p>
23-
<pre>&lt;div class="container"&gt;
23+
<pre><code>&lt;div class="container"&gt;
2424
&lt;h2&gt;Greetings&lt;/h2&gt;
2525
&lt;div class="inner"&gt;Hello&lt;/div&gt;
2626
&lt;div class="inner"&gt;Goodbye&lt;/div&gt;
27-
&lt;/div&gt;</pre>
27+
&lt;/div&gt;</code></pre>
2828
<p>Content can be created and then inserted after several elements at once:</p>
29-
<pre>$('.inner').after('&lt;p&gt;Test&lt;/p&gt;');</pre>
29+
<pre><code>$('.inner').after('&lt;p&gt;Test&lt;/p&gt;');</code></pre>
3030
<p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>
31-
<pre>&lt;div class="container"&gt;
31+
<pre><code>&lt;div class="container"&gt;
3232
&lt;h2&gt;Greetings&lt;/h2&gt;
3333
&lt;div class="inner"&gt;Hello&lt;/div&gt;
3434
&lt;p&gt;Test&lt;/p&gt;
3535
&lt;div class="inner"&gt;Goodbye&lt;/div&gt;
3636
&lt;p&gt;Test&lt;/p&gt;
37-
&lt;/div&gt;</pre>
37+
&lt;/div&gt;</code></pre>
3838
<p>An element in the DOM can also be selected and inserted after another element:</p>
39-
<pre>$('.container').after($('h2'));</pre>
39+
<pre><code>$('.container').after($('h2'));</code></pre>
4040
<p>If an element selected this way is inserted elsewhere, it will be moved rather than cloned:</p>
41-
<pre>&lt;div class="container"&gt;
41+
<pre><code>&lt;div class="container"&gt;
4242
&lt;div class="inner"&gt;Hello&lt;/div&gt;
4343
&lt;div class="inner"&gt;Goodbye&lt;/div&gt;
4444
&lt;/div&gt;
45-
&lt;h2&gt;Greetings&lt;/h2&gt;</pre>
45+
&lt;h2&gt;Greetings&lt;/h2&gt;</code></pre>
4646
<p>If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first.</p>
4747
<h4 id="disconnected-dom-nodes">Inserting Disconnected DOM nodes</h4>
4848
<p>As of jQuery 1.4, <code>.before()</code> and <code>.after()</code> will also work on disconnected DOM nodes. For example, given the following code:</p>
49-
<pre>$('&lt;div/&gt;').after('&lt;p&gt;&lt;/p&gt;');</pre>
49+
<pre><code>$('&lt;div/&gt;').after('&lt;p&gt;&lt;/p&gt;');</code></pre>
5050
<p>The result is a jQuery set containing a div and a paragraph, in that order. That set can be further manipulated, even before it is inserted in the document.</p>
51-
<pre>$('&lt;div/&gt;').after('&lt;p&gt;&lt;/p&gt;').addClass('foo')
51+
<pre><code>$('&lt;div/&gt;').after('&lt;p&gt;&lt;/p&gt;').addClass('foo')
5252
.filter('p').attr('id', 'bar').html('hello')
5353
.end()
54-
.appendTo('body');</pre>
54+
.appendTo('body');</code></pre>
5555
<p>This results in the following elements inserted just before the closing <code>&lt;/body&gt;</code> tag:</p>
56-
<pre>
56+
<pre><code>
5757
&lt;div class="foo"&gt;&lt;/div&gt;
5858
&lt;p class="foo" id="bar"&gt;hello&lt;/p&gt;
59-
</pre>
59+
</code></pre>
6060
<h4 id="passing-a-function">Passing a Function</h4>
6161
<p>As of jQuery 1.4, <code>.after()</code> supports passing a function that returns the elements to insert.</p>
62-
<pre>$('p').after(function() {
62+
<pre><code>$('p').after(function() {
6363
return '&lt;div&gt;' + this.className + '&lt;/div&gt;';
64-
});</pre>
64+
});</code></pre>
6565
<p>This example inserts a <code>&lt;div&gt;</code> after each paragraph, with each new <code>&lt;div&gt;</code> containing the class name(s) of its preceding paragraph.</p>
6666
<h4 id="additional-arguments">Additional Arguments</h4>
6767
<p>Similar to other content-adding methods such as <code><a href="http://api.jquery.com/prepend/">.prepend()</a></code> and <code><a href="http://api.jquery.com/before/">.before()</a></code>, <code>.after()</code> also supports passing in multiple arguments as input. Supported input includes DOM elements, jQuery objects, HTML strings, and arrays of DOM elements.</p>
6868
<p>For example, the following will insert two new <code>&lt;div&gt;</code>s and an existing <code>&lt;div&gt;</code> after the first paragraph:</p>
69-
<pre>var $newdiv1 = $('&lt;div id="object1"/&gt;'),
69+
<pre><code>var $newdiv1 = $('&lt;div id="object1"/&gt;'),
7070
newdiv2 = document.createElement('div'),
7171
existingdiv1 = document.getElementById('foo');
7272

7373
$('p').first().after($newdiv1, [newdiv2, existingdiv1]);
74-
</pre>
74+
</code></pre>
7575
<p>Since <code>.after()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$('p').first().after($newdiv1, newdiv2, existingdiv1)</code>. The type and number of arguments will largely depend on the elements that are collected in the code.</p>
7676
</longdesc>
7777
<example>

entries/ajaxComplete.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request completes, jQuery triggers the <code>ajaxComplete</code> event. Any and all handlers that have been registered with the <code>.ajaxComplete()</code> method are executed at this time.</p>
1313
<p>To observe this method in action, we can set up a basic Ajax load request:</p>
14-
<pre>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
14+
<pre><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
1515
&lt;div class="result"&gt;&lt;/div&gt;
1616
&lt;div class="log"&gt;&lt;/div&gt;
17-
</pre>
17+
</code></pre>
1818
<p>We can attach our event handler to any element:</p>
19-
<pre>$('.log').ajaxComplete(function() {
19+
<pre><code>$('.log').ajaxComplete(function() {
2020
$(this).text('Triggered ajaxComplete handler.');
2121
});
22-
</pre>
22+
</code></pre>
2323
<p>Now, we can make an Ajax request using any jQuery method:</p>
24-
<pre>$('.trigger').click(function() {
24+
<pre><code>$('.trigger').click(function() {
2525
$('.result').load('ajax/test.html');
26-
});</pre>
26+
});</code></pre>
2727
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>
2828
<p><strong>Note:</strong> Because <code>.ajaxComplete()</code> is implemented as a method of jQuery object instances, we can use the <code>this</code> keyword as we do here to refer to the selected elements within the callback function.</p>
2929
<p>All <code>ajaxComplete</code> handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an <code>ajaxComplete</code> handler is executed, it is passed the event object, the <code>XMLHttpRequest</code> object, and the settings object that was used in the creation of the request. For example, we can restrict our callback to only handling events dealing with a particular URL:</p>
3030
<p><strong>Note:</strong> You can get the returned ajax contents by looking at <code>xhr.responseXML</code> or <code>xhr.responseHTML</code> for xml and html respectively.</p>
31-
<pre>$('.log').ajaxComplete(function(e, xhr, settings) {
31+
<pre><code>$('.log').ajaxComplete(function(e, xhr, settings) {
3232
if (settings.url == 'ajax/test.html') {
3333
$(this).text('Triggered ajaxComplete handler. The result is ' +
3434
xhr.responseHTML);
3535
}
36-
});</pre>
36+
});</code></pre>
3737
</longdesc>
3838
<example>
3939
<desc>Show a message when an Ajax request completes.</desc>

entries/ajaxError.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request completes with an error, jQuery triggers the <code>ajaxError</code> event. Any and all handlers that have been registered with the <code>.ajaxError()</code> method are executed at this time.</p>
1313
<p>To observe this method in action, set up a basic Ajax load request.</p>
14-
<pre>&lt;button class="trigger"&gt;Trigger&lt;/button&gt;
14+
<pre><code>&lt;button class="trigger"&gt;Trigger&lt;/button&gt;
1515
&lt;div class="result"&gt;&lt;/div&gt;
16-
&lt;div class="log"&gt;&lt;/div&gt;</pre>
16+
&lt;div class="log"&gt;&lt;/div&gt;</code></pre>
1717
<p>Attach the event handler to any element:</p>
18-
<pre>$("div.log").ajaxError(function() {
18+
<pre><code>$("div.log").ajaxError(function() {
1919
$(this).text( "Triggered ajaxError handler." );
20-
});</pre>
20+
});</code></pre>
2121
<p>Now, make an Ajax request using any jQuery method:</p>
22-
<pre>$("button.trigger").click(function() {
22+
<pre><code>$("button.trigger").click(function() {
2323
$("div.result").load( "ajax/missing.html" );
24-
});</pre>
24+
});</code></pre>
2525
<p>When the user clicks the button and the Ajax request fails, because the requested file is missing, the log message is displayed.</p>
2626
<p><strong>Note:</strong> Because <code>.ajaxError()</code> is implemented as a method of jQuery object instances, you can use the <code>this</code> keyword within the callback function to refer to the selected elements.</p>
2727
<p>All <code>ajaxError</code> handlers are invoked, regardless of what Ajax request was completed. To differentiate between the requests, you can use the parameters passed to the handler. Each time an <code>ajaxError</code> handler is executed, it is passed the event object, the <code>jqXHR</code> object (prior to jQuery 1.5, the <code><abbr title="XMLHttpRequest">XHR</abbr></code> object), and the settings object that was used in the creation of the request. If the request failed because JavaScript raised an exception, the exception object is passed to the handler as a fourth parameter. For example, to restrict the error callback to only handling events dealing with a particular URL:</p>
28-
<pre>$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
28+
<pre><code>$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
2929
if ( settings.url == "ajax/missing.html" ) {
3030
$(this).text( "Triggered ajaxError handler." );
3131
}
32-
});</pre>
32+
});</code></pre>
3333
</longdesc>
3434
<example>
3535
<desc>Show a message when an Ajax request fails.</desc>

entries/ajaxSend.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request is about to be sent, jQuery triggers the <code>ajaxSend</code> event. Any and all handlers that have been registered with the <code>.ajaxSend()</code> method are executed at this time.</p>
1313
<p>To observe this method in action, we can set up a basic Ajax load request:</p>
14-
<pre>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
14+
<pre><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
1515
&lt;div class="result"&gt;&lt;/div&gt;
16-
&lt;div class="log"&gt;&lt;/div&gt;</pre>
16+
&lt;div class="log"&gt;&lt;/div&gt;</code></pre>
1717
<p>We can attach our event handler to any element:</p>
18-
<pre>$('.log').ajaxSend(function() {
18+
<pre><code>$('.log').ajaxSend(function() {
1919
$(this).text('Triggered ajaxSend handler.');
20-
});</pre>
20+
});</code></pre>
2121
<p>Now, we can make an Ajax request using any jQuery method:</p>
22-
<pre>$('.trigger').click(function() {
22+
<pre><code>$('.trigger').click(function() {
2323
$('.result').load('ajax/test.html');
24-
});</pre>
24+
});</code></pre>
2525
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request is about to begin, the log message is displayed.</p>
2626
<p><strong>Note:</strong> Because <code>.ajaxSend()</code> is implemented as a method of jQuery instances, we can use the <code>this</code> keyword as we do here to refer to the selected elements within the callback function.</p>
2727
<p>All <code>ajaxSend</code> handlers are invoked, regardless of what Ajax request is to be sent. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an <code>ajaxSend</code> handler is executed, it is passed the event object, the <code>jqXHR</code> object (in version 1.4, <code>XMLHttpRequest</code>object), and the <a href="http://api.jquery.com/jQuery.ajax/">settings object</a> that was used in the creation of the Ajax request. For example, we can restrict our callback to only handling events dealing with a particular URL:</p>
28-
<pre>$('.log').ajaxSend(function(e, jqxhr, settings) {
28+
<pre><code>$('.log').ajaxSend(function(e, jqxhr, settings) {
2929
if (settings.url == 'ajax/test.html') {
3030
$(this).text('Triggered ajaxSend handler.');
3131
}
32-
});</pre>
32+
});</code></pre>
3333
</longdesc>
3434
<example>
3535
<desc>Show a message before an Ajax request is sent.</desc>

entries/ajaxStart.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the <code>ajaxStart</code> event. Any and all handlers that have been registered with the <code>.ajaxStart()</code> method are executed at this time.</p>
1313
<p>To observe this method in action, we can set up a basic Ajax load request:</p>
14-
<pre>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
14+
<pre><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
1515
&lt;div class="result"&gt;&lt;/div&gt;
16-
&lt;div class="log"&gt;&lt;/div&gt;</pre>
16+
&lt;div class="log"&gt;&lt;/div&gt;</code></pre>
1717
<p>We can attach our event handler to any element:</p>
18-
<pre>$('.log').ajaxStart(function() {
18+
<pre><code>$('.log').ajaxStart(function() {
1919
$(this).text('Triggered ajaxStart handler.');
20-
});</pre>
20+
});</code></pre>
2121
<p>Now, we can make an Ajax request using any jQuery method:</p>
22-
<pre>$('.trigger').click(function() {
22+
<pre><code>$('.trigger').click(function() {
2323
$('.result').load('ajax/test.html');
24-
});</pre>
24+
});</code></pre>
2525
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request is sent, the log message is displayed.</p>
2626
<p><strong>Note:</strong> Because <code>.ajaxStart()</code> is implemented as a method of jQuery object instances, we can use the <code>this</code> keyword as we do here to refer to the selected elements within the callback function.</p>
2727
</longdesc>

entries/ajaxStop.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the <code>ajaxStop</code> event. Any and all handlers that have been registered with the <code>.ajaxStop()</code> method are executed at this time. The <code>ajaxStop</code> event is also triggered if the last outstanding Ajax request is cancelled by returning false within the <code>beforeSend</code> callback function. </p>
1313
<p>To observe this method in action, we can set up a basic Ajax load request:</p>
14-
<pre>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
14+
<pre><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
1515
&lt;div class="result"&gt;&lt;/div&gt;
16-
&lt;div class="log"&gt;&lt;/div&gt;</pre>
16+
&lt;div class="log"&gt;&lt;/div&gt;</code></pre>
1717
<p>We can attach our event handler to any element:</p>
18-
<pre>$('.log').ajaxStop(function() {
18+
<pre><code>$('.log').ajaxStop(function() {
1919
$(this).text('Triggered ajaxStop handler.');
20-
});</pre>
20+
});</code></pre>
2121
<p>Now, we can make an Ajax request using any jQuery method:</p>
22-
<pre>$('.trigger').click(function() {
22+
<pre><code>$('.trigger').click(function() {
2323
$('.result').load('ajax/test.html');
24-
});</pre>
24+
});</code></pre>
2525
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>
2626
<p>Because <code>.ajaxStop()</code> is implemented as a method of jQuery object instances, we can use the <code>this</code> keyword as we do here to refer to the selected elements within the callback function.</p>
2727
</longdesc>

entries/ajaxSuccess.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request completes successfully, jQuery triggers the <code>ajaxSuccess</code> event. Any and all handlers that have been registered with the <code>.ajaxSuccess()</code> method are executed at this time.</p>
1313
<p>To observe this method in action, we can set up a basic Ajax load request:</p>
14-
<pre>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
14+
<pre><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
1515
&lt;div class="result"&gt;&lt;/div&gt;
16-
&lt;div class="log"&gt;&lt;/div&gt;</pre>
16+
&lt;div class="log"&gt;&lt;/div&gt;</code></pre>
1717
<p>We can attach our event handler to any element:</p>
18-
<pre>$('.log').ajaxSuccess(function() {
18+
<pre><code>$('.log').ajaxSuccess(function() {
1919
$(this).text('Triggered ajaxSuccess handler.');
20-
});</pre>
20+
});</code></pre>
2121
<p>Now, we can make an Ajax request using any jQuery method:</p>
22-
<pre>$('.trigger').click(function() {
22+
<pre><code>$('.trigger').click(function() {
2323
$('.result').load('ajax/test.html');
24-
});</pre>
24+
});</code></pre>
2525
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes successfully, the log message is displayed.</p>
2626
<p><strong>Note:</strong> Because <code>.ajaxSuccess()</code> is implemented as a method of jQuery object instances, we can use the <code>this</code> keyword as we do here to refer to the selected elements within the callback function.</p>
2727
<p>All <code>ajaxSuccess</code> handlers are invoked, regardless of what Ajax request was completed. If we must differentiate between the requests, we can use the parameters passed to the handler. Each time an <code>ajaxSuccess</code> handler is executed, it is passed the event object, the <code>XMLHttpRequest</code> object, and the settings object that was used in the creation of the request. For example, we can restrict our callback to only handling events dealing with a particular URL:</p>
2828
<p><strong>Note:</strong> You can get the returned ajax contents by looking at <code>xhr.responseXML</code> or <code>xhr.responseText</code> for xml and html respectively.</p>
29-
<pre>$('.log').ajaxSuccess(function(e, xhr, settings) {
29+
<pre><code>$('.log').ajaxSuccess(function(e, xhr, settings) {
3030
if (settings.url == 'ajax/test.html') {
3131
$(this).text('Triggered ajaxSuccess handler. The ajax response was:'
3232
+ xhr.responseText );
3333
}
34-
});</pre>
34+
});</code></pre>
3535
</longdesc>
3636
<example>
3737
<desc>Show a message when an Ajax request completes successfully.</desc>

0 commit comments

Comments
 (0)