Skip to content

Instantly share code, notes, and snippets.

@jakejscott
Created January 21, 2011 13:44
Show Gist options
  • Save jakejscott/789692 to your computer and use it in GitHub Desktop.
Save jakejscott/789692 to your computer and use it in GitHub Desktop.
Did you know about the jQuery element constructor ninja?
<!doctype>
<html>
<head></head>
<body>
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script>
$(document.body).prepend(
$('<p>', {
id : '123',
class : 'wow',
text : 'I am a paragraph',
title: 'I am a title for this paragraph',
'data-thing' : 'some data',
click : function(){
console.log('click');
},
mouseleave : function(){
console.log('enter');
$(this).css({
color:'red',
background:'#ccc'
});
},
mouseenter : function(){
console.log('leave');
$(this).css({
color:'#ccc',
background:'red'
});
},
css : {
color:'red',
background:'#ccc',
padding : '3px',
margin: '10px'
}
}).click(function(){
console.log('also called')
})
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment