Live data from Hacker News

This Week in Rails: jQuery no longer part of Rails, and more

weblog.rubyonrails.org

141–143 of 143 posts

Re: This Week in Rails: jQuery no longer part of Rails, and more

#141
post #130
post #90

Earlier quoted context omitted.

I have an example to which maybe you or someone else can suggest a better 'vanilla' solution. Would love to hear suggestions. With jQuery I'd often do $( ).on('click', , callback); crucially, because events bubble up, even a click on a child element of will register as a click on the target element. in plain js it doesn't seem to work that way. I'd do .addEventListener(), but I'd run into the problem that the event.t…

Not completely sure what you mean. Could you make a minimal example on jsfiddle? Then I can make the vanilla counterpart and we can compare.

Sorry, no time right now for that. I'll try to explain more clearly. There's no problem if I can bind directly to the element. However, that's often not possible. Imagine a element that is initialized, event listeners and all, but only receives data ( elements) at a later time.

In jQuery I can do something like this:

    $().on('click', , function(e) {
        // using this 'this' gives you the  element. Always. Even 
        // if you click on a child element of . And it works if 
        // you add or remove items. Also it doesn't add a listener 
        // to *every* single item, which matters if you've got a whole 
        // bunch of them!
    });
The vanilla equivalent is often presented to be as simple as:

    .addEventListener('click', function(e) {
        // e.target is the actual element you clicked. So now we need to 
        // figure out if this element is inside an , and perhaps 
        // also *which* . There's various approaches, and it's 
        // not rocket science, but it's all extra work for something that 
        // seems like a common scenario.
    });

Re: This Week in Rails: jQuery no longer part of Rails, and more

#142
post #141
post #130

Earlier quoted context omitted.

Not completely sure what you mean. Could you make a minimal example on jsfiddle? Then I can make the vanilla counterpart and we can compare.

Sorry, no time right now for that. I'll try to explain more clearly. There's no problem if I can bind directly to the element. However, that's often not possible. Imagine a element that is initialized, event listeners and all, but only receives data ( elements) at a later time. In jQuery I can do something like this: $( ).on('click', , function(e) { // using this 'this' gives you the element. Always. Even // if you c…

I still think we should discuss it via a real fiddle we can test the approaches with. Talking about pseudecode with placeholders is much more nebulus then talking about real code.

Re: This Week in Rails: jQuery no longer part of Rails, and more

#143
post #142
post #141

Earlier quoted context omitted.

Sorry, no time right now for that. I'll try to explain more clearly. There's no problem if I can bind directly to the element. However, that's often not possible. Imagine a element that is initialized, event listeners and all, but only receives data ( elements) at a later time. In jQuery I can do something like this: $( ).on('click', , function(e) { // using this 'this' gives you the element. Always. Even // if you c…

I still think we should discuss it via a real fiddle we can test the approaches with. Talking about pseudecode with placeholders is much more nebulus then talking about real code.

http://codepen.io/anon/pen/MbqpGG
Post reply on HN