I
I
Ilya Sidorenko2014-04-15 20:54:01
JavaScript
Ilya Sidorenko, 2014-04-15 20:54:01

How to remove the created DIV in JS?

I create a div by copying it:

var value = this.innerHTML,
    div = this.cloneNode(true);	

  document.querySelector('.my .interests').appendChild(div);

But it is not removed in this way:
function delEl(selector, event, callback) {

  var items = document.querySelectorAll(selector);
  for(var i=0; i<items.length; ++i)
    items[i][event] = callback;

};

  
delEl('.my .interests .el', 'onclick', function(){
  this.remove();	
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Olya Pilipenko, 2014-04-16
@iskros

Delegates are needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question