Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created August 2, 2010 19:43
Show Gist options
  • Save elijahmanor/505193 to your computer and use it in GitHub Desktop.
Save elijahmanor/505193 to your computer and use it in GitHub Desktop.
//Quick Element Contruction Syntax
//Instead of concatenating strings together to build up new HTML elements,
//you can now utilize a new feature inside of jQuery 1.4 for quick element construction.
//You can pass a map of properties as the second parameter to set attributes and wire-up event handlers
//Keep in mind certain elements cannot be created this way due to limitations in some browsers (Internet
//Explorer for example). Elements you will have trouble with include `input` and `button` elements.
$("<a />", {
id: "companyLink",
text: "appendTo",
title: "The jQuery Company",
href: "http://appendTo.com",
rel: "external",
click: function() { alert("Rocks!"); return false; }
}).appendTo('body');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment