Skip to content

Commit b38da66

Browse files
committed
changed title attr on jquery-basics files to jquery-basics, some start on jquery-core
1 parent c0ee36f commit b38da66

File tree

10 files changed

+140
-10
lines changed

10 files changed

+140
-10
lines changed

content/jquery-fundamentals/jquery-basics/attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : jqfundamentals
2+
chapter : jquery-basics
33
section : 4
44
title : Attributes
55
attribution: jQuery Fundamentals

content/jquery-fundamentals/jquery-basics/css-styling-dimensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : jqfundamentals
2+
chapter : jquery-basics
33
section : 3
44
title : CSS, Styling, & Dimensions
55
attribution: jQuery Fundamentals

content/jquery-fundamentals/jquery-basics/document-ready.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : jqfundamentals
2+
chapter : jquery-basics
33
section : 1
44
title : $(document).ready()
55
attribution: jQuery Fundamentals

content/jquery-fundamentals/jquery-basics/exercises.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : jqfundamentals
2+
chapter : jquery-basics
33
section : 7
44
title : Exercises
55
attribution: jQuery Fundamentals

content/jquery-fundamentals/jquery-basics/manipulating-elements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : jqfundamentals
2+
chapter : jquery-basics
33
section : 6
44
title : Manipulating Elements
55
attribution: jQuery Fundamentals

content/jquery-fundamentals/jquery-basics/selecting-elements.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
2-
chapter : "jqfundamentals"
3-
section : "2"
4-
title : "Selecting Elements"
2+
chapter : jquery-basics
3+
section : 2
4+
title : Selecting Elements
5+
attribution: jQuery Fundamentals
56
---
67
## Selecting Elements
78

content/jquery-fundamentals/jquery-basics/traversing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : "qfundamentals
2+
chapter : jquery-basics
33
section : 5
44
title : Traversing
55
attribution: jQuery Fundamentals

content/jquery-fundamentals/jquery-basics/working-with-selections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
chapter : jqfundamentals
2+
chapter : jquery-basics
33
section : 3
44
title : Working with Selections
55
attribution: jQuery Fundamentals
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
chapter : jquery-core
3+
section : 1
4+
title : $ vs $()
5+
attribution: jQuery Fundamentals
6+
---
7+
## $ vs $()
8+
9+
Until now, we’ve been dealing entirely with methods that are called on a jQuery object. For example:
10+
11+
<div class="example" markdown="1">
12+
$('h1').remove();
13+
</div>
14+
15+
Most jQuery methods are called on jQuery objects as shown above;
16+
these methods are said to be part of the `$.fn` namespace, or the “jQuery prototype,” and are best thought of as jQuery object methods.
17+
18+
However, there are several methods that do not act on a selection;
19+
these methods are said to be part of the jQuery namespace, and are best thought of as core jQuery methods.
20+
21+
This distinction can be incredibly confusing to new jQuery users. Here’s what you need to remember:
22+
23+
* Methods called on jQuery selections are in the `$.fn` namespace, and automatically receive and return the selection as this.
24+
* Methods in the $ namespace are generally utility-type methods, and do not work with selections; they are not automatically passed any arguments, and their return value will vary.
25+
26+
There are a few cases where object methods and core methods have the same names, such as `$.each` and `$.fn.each`. In these cases, be extremely careful when reading the documentation that you are exploring the correct method.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
chapter : jquery-core
3+
section : 2
4+
title : Utility Methods
5+
attribution: jQuery Fundamentals
6+
---
7+
## Utility Methods
8+
9+
jQuery offers several utility methods in the $ namespace.
10+
These methods are helpful for accomplishing routine programming tasks.
11+
Below are examples of a few of the utility methods; for a complete reference on jQuery utility methods, visit [http://api.jquery.com/category/utilities/](http://api.jquery.com/category/utilities/ "Utilities documenations on api.jquery.com").
12+
13+
### $.trim
14+
15+
<div class="example" markdown="1">
16+
Removes leading and trailing whitespace.
17+
18+
$.trim(' lots of extra whitespace ');
19+
// returns 'lots of extra whitespace'
20+
</div>
21+
22+
### $.each
23+
24+
<div class="example" markdown="1">
25+
Iterates over arrays and objects.
26+
27+
$.each([ 'foo', 'bar', 'baz' ], function(idx, val) {
28+
console.log('element ' + idx + 'is ' + val);
29+
});
30+
31+
$.each({ foo : 'bar', baz : 'bim' }, function(k, v) {
32+
console.log(k + ' : ' + v);
33+
});
34+
</div>
35+
36+
<div class="note" markdown="1">
37+
### Note
38+
39+
There is also a method `$.fn.each`, which is used for iterating over a selection of elements.
40+
</div>
41+
42+
### $.inArray
43+
44+
<div class="example" markdown="1">
45+
Returns a value's index in an array, or -1 if the value is not in the array.
46+
47+
var myArray = [ 1, 2, 3, 5 ];
48+
49+
if ($.inArray(4, myArray) !== -1) {
50+
console.log('found it!');
51+
}
52+
</div>
53+
54+
### $.extend
55+
56+
<div class="example" markdown="1">
57+
Changes the properties of the first object using the properties of subsequent objects.
58+
59+
var firstObject = { foo : 'bar', a : 'b' };
60+
var secondObject = { foo : 'baz' };
61+
62+
var newObject = $.extend(firstObject, secondObject);
63+
console.log(firstObject.foo); // 'baz'
64+
console.log(newObject.foo); // 'baz'
65+
</div>
66+
67+
<div class="example" markdown="1">
68+
If you don't want to change any of the objects you pass to `$.extend`, pass an empty object as the first argument.
69+
70+
var firstObject = { foo : 'bar', a : 'b' };
71+
var secondObject = { foo : 'baz' };
72+
73+
var newObject = $.extend({}, firstObject, secondObject);
74+
console.log(firstObject.foo); // 'bar'
75+
console.log(newObject.foo); // 'baz'
76+
</div>
77+
78+
### $.proxy
79+
80+
<div class="example" markdown="1">
81+
Returns a function that will always run in the provided scope — that is, sets the meaning of this inside the passed function to the second argument.
82+
83+
var myFunction = function() { console.log(this); };
84+
var myObject = { foo : 'bar' };
85+
86+
myFunction(); // logs window object
87+
88+
var myProxyFunction = $.proxy(myFunction, myObject);
89+
myProxyFunction(); // logs myObject object
90+
</div>
91+
92+
<div class="example" markdown="1">
93+
If you have an object with methods, you can pass the object and the name of a method to return a function that will always run in the scope of the object.
94+
95+
var myObject = {
96+
myFn : function() {
97+
console.log(this);
98+
}
99+
};
100+
101+
$('#foo').click(myObject.myFn); // logs DOM element #foo
102+
$('#foo').click($.proxy(myObject, 'myFn')); // logs myObject
103+
</div>

0 commit comments

Comments
 (0)