Everyone_Else Everyone_Else - 4 months ago 10
jQuery Question

Append is not a function jquery

In the following code, I'd like to be able to append

test_div
to the element that was clicked on. However, I get the error message that
TypeError:
e.srcElement.append
is not a function
.

$(document).ready(function() {

onclick = function (e) {
var test_div = document.createElement("div");
target = e.srcElement
target.append(test_div);
}

$('#dialogue').on('click', onclick);

});


I've tried printing out the type of
e.srcElement
, but it just says
object
, which isn't very helpful. What's the correct way to append an element to the item clicked on?

Answer

.append() is jquery method. You need to convert DOM object into jquery object for using jquery methods:

 $(target).append(test_div);