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.appendis 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?
.append()
is jquery method. You need to convert DOM object into jquery object for using jquery methods:
$(target).append(test_div);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With