Created
August 31, 2009 12:49
-
-
Save twilson63/178445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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