-2

I have the new jquery-1.11.1.min.js I am setting up a click event on a class called '.drop' way before drop exists but it wont fire (unless the element was there at page load). I thought because of migrating from .bind and .click to .on there would be lots on google but I'm finding mostly old things.

google search:

https://www.google.co.uk/search?q=jquery+on+future+click+body+div&oq=jquery+on+future+click+body+div&aqs=chrome..69i57.14483j0j4&sourceid=chrome&espv=2&es_sm=122&ie=UTF-8

I found this jQuery .on function for future elements, as .live is deprecated and this event fired by a future loaded element

but my code is the same as the answers and still it does nothing

I have a div.btn on the page at the start

Javascript:

$('body').on('click','.btn',function(){//this does happen!
    $('body').append('<div class="drop"></div>');
    });

$('body').on('click','.drop',function(e){console.dir(e);});//this never happens
Community
  • 1
  • 1
8DK
  • 704
  • 1
  • 5
  • 15

1 Answers1

1

Unless you have class="body" I believe you are wanting the <body> tag which makes your current selector invalid...remove the dot

$('body')

Make sure body exists when code is run

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • oops my bad!! I don't have that dot in my code. I have removed it from my question well spotted thank you ('.body' is now 'body' as it should be!). ps: 'body' exists as this is waay after document ready. +1 btw – 8DK Jul 19 '14 at 15:55