Tarjo Tarjo - 1 year ago 113
Javascript Question

RemoveChild does not work

I have a problem with the use of the javascript removeChild function.
Here's my script:

////function to add element by ID////
var i=1;
$("#buttonAdd").live('click',function() {
$("#list1 li:last-child").parent().append('<li>'+
'<label for=njajal[]>njajal'+
'<textarea class="tinymce" name="njajal[]" id="aaa'+i+'"></textarea>'+
'<span><a class="delIt" id="'+i+'"><b>Hapus</a></span></label>'+
tinyMCE.execCommand('mceAddControl', false, 'aaa'+i);
console.log('add '+i);

////Function to delete element by ID/////
function delIt(eleId)
d = document;
var ele = d.getElementById(eleId);
var parentEle = d.getElementById('njajal');

What is the problem?

Here's the HTML code:

<div id="form">
<form method="post" action="">
<ol id="list1">
<label for="njajal[]">njajal
<textarea name="njajal[]" class="tinymce" ></textarea>
<div id="addOpt">
<a id="buttonAdd" class="bt"><b>Tambah</a>

enter image description here

Answer Source

You use jQuery in your first function, so the easiest way to remove that element would be with jQuery:


Here's how you can accomplish the same thing with plain javascript:

var myElement = document.getElementById('myElementID');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download