I
I
Ilya Sidorenko2014-04-07 17:11:30
JavaScript
Ilya Sidorenko, 2014-04-07 17:11:30

How to write in "pure" JavaScript the given jQuery example?

How to write it in "pure" JavaScript?

$('.elements div').click(function() {
        $(this).remove();
    });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Shvedov, 2014-04-07
@iskros

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

pureJSEvent('.elements div', 'onclick', function(){
  this.remove();
});

B
Blah Blag, 2014-04-07
@dsadasdad

Look at how a selection is made on the javascript by selectors and how to remove an element from thoughts, then

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question