In the past I've used the following format to create click event handlers in jquery for example if I have the following html
<div class="new-folder">Click me</div>
And then use this jQuery to assign a click handler and filter the click.
$('div').on('click','.new-folder',function(){});
That would catch all the clicks on a div element with the appropriate class, but only run the function if the element had a class of new-folder. and that works great.
But if I try to filter the click events on a button element like this:
<button type="button" class="new-folder">Click me</button>
The selector (below) doesn't work for me.
$('button').on('click','.new-folder',function(){});
If I move the class to the original item selector it does work. So this line (below) does work as expected.
$('button.new-folder').on('click',function(){});
I had always though the filter approach was better because it worked with dynamic content, i.e. if the button doesn't have the class or is added with code after the handler is assigned the filter approach works, but the approach without the filter will fail.
I'm sure there is something very simple I'm missing here. What is different about buttons?
Using jQuery 1.10.2 if that matters.
$('body').on('click','button.new-folder',function(){});