Skip to content

updated formatting #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions page/events/event-delegation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ method is available, and is the preferred method.
</div>

```
//Event delegation using `$.fn.delegate`

$('#myUnorderedList').delegate('li', 'click', function(e) {
var $myListItem = $(this);
// ...
});
// Event delegation using `$.fn.delegate`
$('#myUnorderedList').delegate('li', 'click', function(e) {
var $myListItem = $(this);
// ...
});
```

```
//Event delegation using `$.fn.live`
$('#myUnorderedList li').live('click', function(e) {
var $myListItem = $(this);
// ...
});
// Event delegation using `$.fn.live`
$('#myUnorderedList li').live('click', function(e) {
var $myListItem = $(this);
// ...
});
```

### Unbinding Delegated Events
Expand All @@ -49,7 +48,7 @@ use `$.fn.undelegate` for events connected with `$.fn.delegate`, and `$.fn.die`
for events connected with `$.fn.live`. As with bind, you can optionally pass
in the name of the bound function.
```
//Unbinding delegated events
$('#myUnorderedList').undelegate('li', 'click');
$('#myUnorderedList li').die('click');
// Unbinding delegated events
$('#myUnorderedList').undelegate('li', 'click');
$('#myUnorderedList li').die('click');
```
7 changes: 4 additions & 3 deletions page/events/event-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ When defined, these string properties specify that a special event should be han

The behavior of these properties is easiest to see with an example. Assume a special event defined as follows:

```jQuery.event.special.pushy = {
```
jQuery.event.special.pushy = {
bindType: "click",
delegateType: "click"
};
Expand All @@ -112,10 +113,10 @@ So given the special event above, this code shows that a pushy isn't removed by
```
var $p = $("p");
$p.on("click", function( e ) {
$("body").append("I am a " + e.type + "!"));
$("body").append("I am a " + e.type + "!"));
});
$p.on("pushy", function( e ) {
$("body").append("I am pushy but still a " + e.type + "!");
$("body").append("I am pushy but still a " + e.type + "!");
});
$p.trigger("click"); // triggers both handlers
$p.off("click");
Expand Down
10 changes: 5 additions & 5 deletions page/events/event-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Prior to jQuery 1.4, the `$.fn.hover` method required two functions.
</div>

```
//The hover helper function
$('#menu li').hover(function() {
$(this).toggleClass('hover');
});
// The hover helper function
$('#menu li').hover(function() {
$(this).toggleClass('hover');
});
```

### `$.fn.toggle`
Expand All @@ -31,7 +31,7 @@ however, it will accept an unlimited number of functions. Be careful, though:
providing a long list of functions can be difficult to debug.

```
//The toggle helper function
// The toggle helper function
$('p.expander').toggle(
function() {
$(this).prev().addClass('open');
Expand Down
16 changes: 8 additions & 8 deletions page/events/events-to-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ when you are working with custom events, or when you want to pass an object of
multiple events and handlers.

```
//Event binding using a convenience method
// Event binding using a convenience method
$('p').click(function() {
console.log('click');
});
```

```
//Event biding using the `$.fn.bind` method
// Event biding using the `$.fn.bind` method
$('p').bind('click', function() {
console.log('click');
});
```

```
//Event binding using the `$.fn.bind` method with data
// Event binding using the `$.fn.bind` method with data
$('input').bind(
'click change', // bind to multiple events
{ foo : 'bar' }, // pass in data
Expand All @@ -43,7 +43,7 @@ want no handler to run, or you may want a different handler to run. jQuery
provides the `$.fn.one` method for this purpose.

```
//Switching handlers using the `$.fn.one` method
// Switching handlers using the `$.fn.one` method
$('p').one('click', function() {
console.log('You just clicked this for the first time!');
$(this).click(function() { console.log('You have clicked this before!'); });
Expand All @@ -61,12 +61,12 @@ you can isolate the unbinding to that named function by passing it as the
second argument.

```
//Unbinding all click handlers on a selection
// Unbinding all click handlers on a selection
$('p').unbind('click');
```

```
//Unbinding a particular click handler, using a reference to the function
// Unbinding a particular click handler, using a reference to the function
var foo = function() { console.log('foo'); };
var bar = function() { console.log('bar'); };

Expand All @@ -81,7 +81,7 @@ useful to namespace your events so you don't unintentionally disconnect events
that you didn't or couldn't know about.

```
//Namespacing events
// Namespacing events
$('p').bind('click.myNamespace', function() { /* ... */ });
$('p').unbind('click.myNamespace');
$('p').unbind('.myNamespace'); // unbind all events in the namespace
Expand All @@ -95,7 +95,7 @@ an object into `$.fn.bind` with one or more key/value pairs, with the key being
the event name and the value being the function to handle the event.

```
//Binding Multiple Events
// Binding Multiple Events
$('p').bind({
'click': function() { console.log('clicked!'); },
'mouseover': function() { console.log('hovered!'); }
Expand Down
16 changes: 8 additions & 8 deletions page/events/inside-event-handling-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ simply do $(this), often following this idiom:
```

```
//Preventing a link from being followed
$('a').click(function(e) {
var $this = $(this);
if ($this.attr('href').match('evil')) {
e.preventDefault();
$this.addClass('evil');
}
});
// Preventing a link from being followed
$('a').click(function(e) {
var $this = $(this);
if ($this.attr('href').match('evil')) {
e.preventDefault();
$this.addClass('evil');
}
});
```
Loading