I'm updating and old project from jQuery 1.4 to jQuery 1.7.
Can this be simplified, thus reducing the amount of code, and perhaps in such reduction, have it improved?
Having the following code:
var cartItemDel = '<td class="del"><img src="components/themes/default/img/icons/cross-small.png" width="16" height="16" alt="X"><input type="hidden" class="lid" name="lineID'+ id +'" value="'+ id +'"><span class="hidden token">'+token+'</span></td>',
cartItemName = '<td><input class="CartItemId" type="hidden" name="id_'+ id +'" value="'+ id +'"><span class="CartItemName">'+ name +'</span></td>',
cartItemPrice = '<td><input class="CartItemRef" type="hidden" name="ref_'+ ref +'" value="'+ ref +'"><span class="class="CartItemPrice"><span class="lineSum">'+ price +'</span>€</span></td>';
$(".cart-table tbody")
.append('<tr>'+cartItemDel+cartItemName+cartItemPrice+'</tr>');
I've updated it to:
/*
* ADD NEW LINE - First TD
*/
var $newLineIcon = $("<img/>", {
src : "components/themes/default/img/icons/cross-small.png",
width : "16",
height : "16",
alt : "X"
});
var $newLineLID = $("<input/>", {
type : "hidden",
class : "lid",
name : "lineID"+ lid,
value : lid
});
var $newLineToken = $("<span/>", {
class : "hidden token",
text : token
});
var $newLine_firstTD = $("<td/>", { class : "del"})
.append($newLineIcon)
.append($newLineLID)
.append($newLineToken);
/*
* ADD NEW LINE - Second TD
*/
var $newLinePID = $("<input/>", {
type : "hidden",
class : "CartItemId",
name : "id_"+ id,
value : id
});
var $newLinePNAME = $("<span/>", {
class : "CartItemName",
text : name
});
var $newLine_secondTD = $("<td/>")
.append($newLinePID)
.append($newLinePNAME);
/*
* ADD NEW LINE - Third TD
*/
var $newLinePREF = $("<input/>", {
type : "hidden",
class : "CartItemRef",
name : "ref_"+ ref,
value : ref
});
var $newLinePPRICE = $("<span/>", {
class : "CartItemPrice",
html : "€"
})
.prepend($("<span/>", {class : "lineSum", text : price}));
var $newLine_thirdTD = $("<td/>")
.append($newLinePREF)
.append($newLinePPRICE);
$("<tr/>")
.append($newLine_firstTD)
.append($newLine_secondTD)
.append($newLine_thirdTD)
.appendTo($(".cart-table tbody"));