Skip to content

Instantly share code, notes, and snippets.

@twilson63
Created August 31, 2009 12:49
Show Gist options
  • Save twilson63/178445 to your computer and use it in GitHub Desktop.
Save twilson63/178445 to your computer and use it in GitHub Desktop.
/* Example: */
$.each([objects], function() {
$('tbody').append("<tr><td>" + this.id + "</td><td>" + this.name + "</td></tr>");
});
/*
Simple, example, but you can imagine 10 columns or formated "ul"'s could get really ugly and a lot of string manipulation. Also the fact you could easily miss a lt or gt, and not know.
So we came up with jTag to make it more readable, and to have javascript handle the lt and gt for us.
*/
$.each([objects], function() {
$('tbody').append(
jTag('tr',
jTag('td', this.id) +
jTag('td', this.name)
)
);
});
/*
For us, it seems to make it more readable as well as eliminate the string concat error issue. Where it gets really helpful is in css, and attributes.
For example:
*/
$.each([objects], function() {
$('tbody').append("<tr class='odd'><td id='record-" + this.id + "'>" + this.id + "</td><td>" + this.name + "</td></tr>");
});
/*
jTag
*/
$.each([objects], function() {
$('tbody').append(
jTag('tr',
jTag('td', this.id, jAt('id', 'record-' + this.id)) +
jTag('td', this.name),
jAt('class','odd')
)
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment