Skip to content

Commit d244c32

Browse files
bobholtajpiano
authored andcommitted
apply core styles to using-jquery-core sectione examples
1 parent aa4e46c commit d244c32

15 files changed

+385
-318
lines changed

order.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- feature-browser-detection
3434
- utility-methods
3535
- iterating
36+
- understanding-index
3637
- events:
3738
- introduction-to-events
3839
- handling-events

page/using-jquery-core/attributes.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ or an object containing one or more key/value pairs.
1111

1212
```
1313
// Setting attributes
14-
$('a').attr('href', 'allMyHrefsAreTheSameNow.html');
15-
$('a').attr({
16-
'title' : 'all titles are the same too!',
17-
'href' : 'somethingNew.html'
14+
$("a").attr( "href", "allMyHrefsAreTheSameNow.html" );
15+
16+
$("a").attr({
17+
"title" : "all titles are the same too!",
18+
"href" : "somethingNew.html"
1819
});
1920
```
2021

2122
This time, we broke the object up into multiple lines. Remember, whitespace
22-
doesn't matter in JavaScript, so you should feel free to use it liberally to
23+
doesn"t matter in JavaScript, so you should feel free to use it liberally to
2324
make your code more legible! You can use a minification tool later to strip out
2425
unnecessary whitespace for production.
2526

2627
```
2728
// Getting attributes
28-
$('a').attr('href'); // returns the href for the first a element in the document
29+
$("a").attr("href"); // returns the href for the first a element in the document
2930
```

page/using-jquery-core/avoid-conflicts-other-libraries.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ variable name to replace `$`.
1717
<!-- Putting jQuery into no-conflict mode -->
1818
<script src="prototype.js"></script>
1919
<script src="jquery.js"></script>
20-
<script>var $j = jQuery.noConflict();</script>
20+
<script>
21+
22+
var $j = jQuery.noConflict();
23+
24+
</script>
2125
```
2226

2327
You can continue to use the standard $ by wrapping your code in a
@@ -30,10 +34,13 @@ over the `$`.
3034
<script src="prototype.js"></script>
3135
<script src="jquery.js"></script>
3236
<script>
37+
3338
jQuery.noConflict();
3439
3540
(function($) {
41+
3642
// your code here, using the $
37-
})(jQuery);
43+
44+
})( jQuery );
3845
</script>
3946
```

page/using-jquery-core/css-styling-dimensions.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ will work.
1717

1818
```
1919
// Getting CSS properties
20-
$('h1').css('fontSize'); // returns a string such as "19px"
21-
$('h1').css('font-size'); // also works
20+
$("h1").css("fontSize"); // returns a string such as "19px"
21+
$("h1").css("font-size"); // also works
2222
```
2323

2424
```
2525
// Setting CSS properties
26-
$('h1').css('fontSize', '100px'); // setting an individual property
27-
$('h1').css({ 'fontSize' : '100px', 'color' : 'red' }); // setting multiple properties
26+
$("h1").css( "fontSize", "100px" ); // setting an individual property
27+
28+
$("h1").css({
29+
"fontSize": "100px",
30+
"color": "red"
31+
}); // setting multiple properties
2832
```
2933

3034
Note the style of the argument we use on the second line — it is an object that
@@ -44,13 +48,13 @@ class on the element you want to affect.
4448

4549
```
4650
// Working with classes
47-
var $h1 = $('h1');
51+
var $h1 = $("h1");
4852
49-
$h1.addClass('big');
50-
$h1.removeClass('big');
51-
$h1.toggleClass('big');
53+
$h1.addClass("big");
54+
$h1.removeClass("big");
55+
$h1.toggleClass("big");
5256
53-
if ($h1.hasClass('big')) { ... }
57+
if ( $h1.hasClass("big") ) { ... }
5458
```
5559

5660
Classes can also be useful for storing state information about an element, such as indicating that an element is selected.
@@ -65,13 +69,13 @@ methods, visit the [Dimensions documentation on api.jquery.com](http://api.jquer
6569

6670
```
6771
// Basic dimensions methods
68-
$('h1').width('50px'); // sets the width of all H1 elements
69-
$('h1').width(); // gets the width of the first H1
72+
$("h1").width("50px"); // sets the width of all H1 elements
73+
$("h1").width(); // gets the width of the first H1
7074
71-
$('h1').height('50px'); // sets the height of all H1 elements
72-
$('h1').height(); // gets the height of the first H1
75+
$("h1").height("50px"); // sets the height of all H1 elements
76+
$("h1").height(); // gets the height of the first H1
7377
74-
$('h1').position(); // returns an object containing position
78+
$("h1").position(); // returns an object containing position
7579
// information for the first H1 relative to
7680
// its "offset (positioned) parent"
7781
```

page/using-jquery-core/data-methods.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ store data related to an element, and it manages the memory issues for you.
1313

1414
```
1515
// Storing and retrieving data related to an element
16-
$('#myDiv').data('keyName', { foo : 'bar' });
17-
$('#myDiv').data('keyName'); // { foo : 'bar' }
16+
$("#myDiv").data( "keyName", { foo: "bar" } );
17+
$("#myDiv").data("keyName"); // { foo: "bar" }
1818
```
1919

2020
You can store any kind of data on an element, and it's hard to overstate the
@@ -30,15 +30,20 @@ list item using `$.fn.data`:
3030

3131
```
3232
// Storing a relationship between elements using $.fn.data
33-
$('#myList li').each(function() {
34-
var $li = $(this), $div = $li.find('div.content');
35-
$li.data('contentDiv', $div);
33+
$("#myList li").each(function() {
34+
35+
var $li = $( this );
36+
var $div = $li.find("div.content");
37+
38+
$li.data( "contentDiv", $div );
39+
3640
});
3741
3842
// later, we don't have to find the div again;
3943
// we can just read it from the list item's data
40-
var $firstLi = $('#myList li:first');
41-
$firstLi.data('contentDiv').html('new content');
44+
var $firstLi = $("#myList li:first");
45+
46+
$firstLi.data("contentDiv").html("new content");
4247
```
4348

4449
In addition to passing `$.fn.data` a single key-value pair to store data, you can also pass an object containing one or more pairs.
+41-30
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,74 @@
11
---
2-
title : $(document).ready()
2+
title : $( document ).ready()
33
level: beginner
44
---
5-
You cannot safely manipulate a page until the document is “ready.”
6-
jQuery detects this state of readiness for you; code included inside
7-
`$(document).ready()` will only run once the page DOM (Document Object Model) is ready for JavaScript code to execute
8-
whereas `$(window).load(function () {})` will run once the entire page (images or iframe) not just the DOM is ready.
9-
10-
``` js
11-
// A $(document).ready() block
12-
$(document).ready(function() {
13-
console.log('ready!');
5+
You cannot safely manipulate a page until the document is “ready.”
6+
jQuery detects this state of readiness for you; code included inside
7+
`$( document ).ready()` will only run once the page DOM (Document Object Model) is ready for JavaScript code to execute
8+
whereas `$( window ).load(function () {})` will run once the entire page (images or iframe) not just the DOM is ready.
9+
10+
```
11+
// A $( document ).ready() block
12+
$( document ).ready(function() {
13+
14+
console.log("ready!");
15+
1416
});
1517
```
1618

17-
There is a shorthand for `$(document).ready()` that you will sometimes see; however,
18-
I recommend against using it if you are writing code that people who aren't experienced
19+
There is a shorthand for `$( document ).ready()` that you will sometimes see; however,
20+
I recommend against using it if you are writing code that people who aren't experienced
1921
with jQuery may see.
2022

21-
``` js
22-
// Shorthand for $(document).ready()
23+
```
24+
// Shorthand for $( document ).ready()
2325
$(function() {
24-
console.log('ready!');
26+
27+
console.log("ready!");
28+
2529
});
2630
```
2731

2832
You can also pass a named function to `$(document).ready()` instead of passing an anonymous function.
2933

30-
``` js
34+
```
3135
// Passing a named function instead of an anonymous function
3236
3337
function readyFn( jQuery ) {
38+
3439
// code to run when the document is ready
40+
3541
}
3642
37-
$(document).ready(readyFn);
43+
$( document ).ready( readyFn );
3844
39-
// OR
45+
// OR
4046
41-
$(window).load(readyFn);
47+
$( window ).load( readyFn );
4248
```
4349

44-
Let's take a look at how both the events act. The below example tries to load some website url in an iframe and checks for both the events.
50+
Let's take a look at how both the events act. The below example tries to load some website url in an iframe and checks for both the events.
4551
``` html
4652
<html>
4753
<head>
4854
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
49-
<script>
50-
$(document).ready(function () {
51-
console.log('document loaded');
52-
});
53-
54-
$(window).load(function () {
55-
console.log('window loaded');
56-
});
57-
</script>
55+
<script>
56+
57+
$( document ).ready(function () {
58+
59+
console.log("document loaded");
60+
61+
});
62+
63+
$( window ).load(function () {
64+
65+
console.log("window loaded");
66+
67+
});
68+
</script>
5869
</head>
5970
<body>
60-
<iframe src='http://techcrunch.com'></iframe>
71+
<iframe src="http://techcrunch.com"></iframe>
6172
</body>
6273
</html>
6374
```

page/using-jquery-core/dollar-object-vs-function.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Until now, we’ve been dealing entirely with methods that are called on a jQuer
99
object. For example:
1010

1111
```
12-
$('h1').remove();
12+
$("h1").remove();
1313
```
1414

1515
Most jQuery methods are called on jQuery objects as shown above; these methods

0 commit comments

Comments
 (0)