I created a div.box in the html and in it I want to insert another div that I create in the code execution, follow the abbreviation:
HTML:
<div class="box"></div>
JS:
var item = $('<div />', {class: 'item'})
var box = $('.box')
box.on('click', function (e) {
this.append(item)
})
But instead of appearing the div.item inside div.box appears the text [object Object]. I realized that this only happens when executed in the click event, doing the form below works:
var item = $('<div />', {class: 'item'})
var box = $('.box')
box.append(item)
Does anyone have an explanation for this?