Jquery Plugin HelloWord

simple example create jquery plugin

helloword.js


(function( $ ) {
$.fn.HelloWord = function(){
var html = $(this).html();
return $(this).html(html + ' Hello Word');
}

}( jQuery ));

test.html


<!DOCTYPE HTML>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="helloword.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<body>
<h1>this H1 tag</h1>
<span>this span tag</span>
<div>this div tag</div>
<a>this a tag</a>

<script>
$(document).ready(
function(){
$('a').HelloWord();
$('h1').HelloWord();
}
);
</script>
</body>
</html>

test it

jquery-plugin-hello-word

Published by

G3n1k

just to remember what i had known :)

One thought on “Jquery Plugin HelloWord”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s