Skip to content

Instantly share code, notes, and snippets.

@tomaskavalek
Created January 24, 2011 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaskavalek/793625 to your computer and use it in GitHub Desktop.
Save tomaskavalek/793625 to your computer and use it in GitHub Desktop.
jQuery create element demo.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="copyright" content="" />
<meta name="author" content="" />
<meta name="robots" content="all, follow" />
<meta name="googlebot" content="index, follow, snippet, archive" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var el = $('<a>', {
href: 'http://www.google.com/',
text: 'title',
onclick: function() {
alert(this.href);
},
onmouseover: function() {
// this.style.color = 'green'
$(this).css('color', 'green')
},
onmouseout: function() {
// this.style.color = 'red'
$(this).css('color', 'red')
},
css: {
color: 'red'
}
});
$('div#main').html(el);
});
</script>
<title></title>
</head>
<body>
<div id="main">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment