javascriptでボタンを作成してリストアイテムに貼り付けましたが、作成した同じボタンで削除することはできません。ここに私が始めたものがあります。どんな助けも素晴らしいだろう。ありがとう。javascriptでダイナミックに作成されたボタンでリスト項目を削除する方法
//creating remove button works fine, problem is deleting the list item
var button = document.createElement('button');
var txt = document.createTextNode('\u00D7');
button.id = "close";
button.appendChild(txt);
item.appendChild(button);
list.insertBefore(item, list.childNodes[0]);
}
// this is what I came up with but it does not work.
// I do get an error "Cannot set property 'onclick' of null."
var close = document.getElementById('close')
close.onclick = function() {
var div = this.parentElement;
div.style.display = 'none';
}
フィドルを作成できますか? –
こんにちは、これが助けてくれることを願っています。 https://jsfiddle.net/alexpham23/33g6jdk1/ –