L
L
Lietorick2015-09-20 20:44:32
JavaScript
Lietorick, 2015-09-20 20:44:32

What is the difference and which is better?

var body = $('#items').find('tbody'), i = 0, temp;
                body.empty();
                if (res.length > 0) {
                    for (; i < res.length; i++) {
                        temp = $('<tr>');
                        temp.append($('<td>' + res[i]['name'] + '</td>'));
                        temp.append('<td>' + res[i]['price'] + '</td>');
                        body.append(temp)
                    }
                } else {
                    body.append($('<tr><td colspan="2" class="text-center">Товары отсутствуют</td></tr>'))
                }


So: Syak: Or otherwise?
temp.append($('<td>' + res[i]['name'] + '</td>'));

temp.append('<td>' + res[i]['name'] + '</td>');

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-09-20
@Lietorick

It doesn't matter (except perhaps an extra "waste of resources" for calling $ when it's not needed), it's just that the append method understands this and that.

S
Sergey, 2015-09-20
Protko @Fesor

Is it otherwise?

Use templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question