On 17/08/06, Michael Geary <[EMAIL PROTECTED]> wrote:
> > From: Aloyzas Rimeika
> >
> > ...But I recommend use $.dom plugin only in XHTML pages with
> > MIME type application/xhtml+xml
> > http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_in_xh.html
> >
> > Easier and faster solution is innerHTML
> > http://www.quirksmode.org/dom/innerhtml.html
> >
> > For example:
> > var json = [
> >    {'name' : "John", 'surname' : "Smith"},
> >    {'name' : "Sarra", 'surname' : "Smith"} ];
> >
> > var table = $('#fill-table > tbody');
> > $.each(json, function(){
> >    table.append('<tr class="MyTableRow">'
> >       +'<td class="MyTableCol1">'+ this.name
> >       +'<td class="MyTableCol2">'+ this.surname
> >    +'</tr>');
> > });
>
> I'm with you there. I have switched most of my code from DOM creation to
> innerHTML.
>
> BTW, you can speed up this kind of code by using Array.join instead of
> string concatenation:
>
>  var table = $('#fill-table > tbody');
>  $.each(json, function(){
>     table.append( [
>         '<tr class="MyTableRow">',
>             '<td class="MyTableCol1">', this.name, '</td>',
>             '<td class="MyTableCol2">', this.surname, '</td>',
>         '</tr>'
>     ].join('') );
>  });
>
> It won't make a huge difference in a simple case like this, but if you're
> concatenating very many strings, Array.join really speeds things up in most
> browsers.
>
> -Mike
>

Doesn't this work:

$('#fill-table > tbody').append(json, [
       '<tr class="MyTableRow">',
           '<td class="MyTableCol1">', this.name, '</td>',
           '<td class="MyTableCol2">', this.surname, '</td>',
       '</tr>'
   ].join('');
 );

If not, perhaps it should be added to jQuery?

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to