Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Last active December 14, 2015 02:09
Show Gist options
  • Save elijahmanor/5011216 to your computer and use it in GitHub Desktop.
Save elijahmanor/5011216 to your computer and use it in GitHub Desktop.
jQuery Event Binding: Click/Bind
<div data-role="page">
<div data-role="header">
<h1>jQuery Board Members</h1>
</div>
<div data-role="content">
<ul id="members" data-role="listview" data-filter="true">
<li>
<a href="index.html">
<h3>Scott González</h3>
<p>jQuery UI Development Lead</p>
</a>
</li>
<li>
<a href="index.html">
<h3>Rick Waldron</h3>
<p>jQuery Core</p>
</a>
</li>
<li>
<a href="index.html">
<h3>Dave Methvin</h3>
<p>jQuery Core Lead &amp; President</p>
</a>
</li>
</ul>
</div>
<button id="addMember">Add Member</button>
</div>
$( document ).bind( "pageinit", function() {
$( "#addMember" ).click( function() {
var markup = '<li><a href="index.html"><h3>John Resig</h3><p>jQuery Core Lead</p></a></li>',
$members = $( "#members" );
$( markup ).appendTo( $members );
$members.listview( "refresh" );
});
$( "#members li" ).click( function( e ) {
e.preventDefault();
console.log( "Clicked " + $( this ).find( "h3" ).text() );
});
});
name: jQuery Event Binding Bind Method
description: jQuery Event Binding Example using the Bind Method
authors:
- Elijah Manor
resources:
- http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css
- http://code.jquery.com/jquery-1.8.2.min.js
- http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js
normalize_css: no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment