12/14 Append to Body


Would someone be nice to explain what's the purpose of + toAdd +?

why do we need the plus sign? when not just this 'toAdd'?

$(document).ready(function() {
    $("#button").click(function() {
        var toAdd = $("input[name=checkListItem]").val();
        $(".list").append('<div class="item">' + toAdd + '</div');


Because if you don't include the + signs, the computer wouldn't know what you want it to do. The + signs tell the computer to add two things together. In this case, you want to add
<div class="item">' and ("input[name=checkListItem]").val() and a closing tag, '</div>'.

When you put + signs the computer thinks "I have to put this string together with this variable and finally together with this string". Otherwise the computer thinks "ERROR ERROR ERROR".


I'm curious why we need to add so many hypotheses. Why can't it be:


+ toAdd + </div');

Why does the beginning and closing div tag need its own set of hypotheses?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.