Skip to content

Instantly share code, notes, and snippets.

@AntMooreWebDev
Created February 8, 2017 16:44
Show Gist options
  • Save AntMooreWebDev/bbd29b7f5298409dba12aed9a71ee81b to your computer and use it in GitHub Desktop.
Save AntMooreWebDev/bbd29b7f5298409dba12aed9a71ee81b to your computer and use it in GitHub Desktop.
A function to dynamically create a HTML element, with the ability to specify an on-click function.
function createEl (elType, elId, elClass, onClik, elText) {
return $('<' + elType + '>', {
id: elId,
'class': elClass,
text: elText,
on: {
click: onClik
}
});
}
$('body').append(
createEl("div", null, "col-md-6 col-md-offset-3", null, null).append(
createEl("div", "mediaArea", null, null, null)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment