Last active
August 29, 2015 14:08
-
-
Save oiler/92e7cabb63c768c2720a to your computer and use it in GitHub Desktop.
jQuery plugin authoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
http://blog.teamtreehouse.com/writing-your-own-jquery-plugins | |
http://programmers.stackexchange.com/questions/160732/function-declaration-as-var-instead-of-function | |
--> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport", content="width=device-width"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
</head> | |
<body> | |
<h1>Hello, World</h1> | |
<h2>Hello, World</h2> | |
<h3>Hello, World</h3> | |
<script> | |
(function($) { | |
// jquery object dot notation | |
$.fn.pizza = function( customText ) { | |
$(this).text( customText ); | |
} | |
// statement, is hoisted | |
function slice( customText ) { | |
$('h2').text( customText ); | |
} | |
// expression, you define when and what it uses | |
var pie = function( customText ) { | |
$('h3').text( customText ); | |
} | |
$(document).ready(function(){ | |
$('h1').pizza('Hello, Pizza'); | |
slice('Hello, Slice'); | |
pie('Hello, Pie'); | |
}); | |
}(jQuery)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment