Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Created December 1, 2013 11:53
Show Gist options
  • Save RalfAlbert/7732687 to your computer and use it in GitHub Desktop.
Save RalfAlbert/7732687 to your computer and use it in GitHub Desktop.
Custom events with jQuery
<h1>jQuery Testseite</h1>
<p id="test">Hello World!</p>
<p><a href="#" id="clickit">Click it!</a></p>
<script type="text/javascript">
$(document).ready(
function() {
$('#test').bind(
'colorChange',
function() {
console.log('Color changed!');
}
);
$('#clickit').click(
function(){
$('#test').css('color', 'Red');
$('#test').trigger('colorChange')
}
);
}
);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment