$('body').on('click', '.anything', function() { //code });
doesn't work for anything right now and I can't figure out why. I'm able to anchor to anything else, say I just toss a #wrap
div right inside the body
. Then I'm able to do
$('#wrap').on('click', '.anything', function() { //code });
for any element I want.
Any idea what I could have done to disable this ability on the body element?
Thanks!
You should use $(document)
. It is a function trigger for any click event in the document. Then inside you can use the jquery on("click","body *",somefunction)
, where the second argument specifies which specific element to target. In this case every element inside the body.
$(document).on('click','body *',function(){ // $(this) = your current element that clicked. // additional code });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With