Skip to main content

Bug Tracker

Side navigation

#12437 closed bug (notabug)

Opened August 31, 2012 10:44PM UTC

Closed September 17, 2012 04:41PM UTC

Last modified October 01, 2012 12:21PM UTC

.on() not working on version 1.8.1 after ajax call

Reported by: jgleiser Owned by: jgleiser
Priority: blocker Milestone: 1.8.2
Component: event Version: 1.8.1
Keywords: Cc:
Blocked by: Blocking:
Description

I have the following code before the $.ajax function

var resultados = $("#resultados-filtro");

resultados.find(".list-pager").on("click",'a',function(e){e.preventDefault();});

resultados.find('.ver-detalles').on('click', function(e){e.preventDefault();});

resultados.find('.comparar').on('click', function(e){e.preventDefault();});

And I have the following function inside an $.ajax call after success

success: function(data, textStatus, jqXHR){

resultados.find(".list-pager").off("click",'a');

resultados.find('.ver-detalles').off('click');

resultados.find('.comparar').off('click');

resultados.html($(data).find("#tabla-resultados"));

resultados.find(".list-pager").on("click",'a',function(e){e.preventDefault();});

resultados.find('.ver-detalles').on('click', function(e){e.preventDefault();});

resultados.find('.comparar').on('click', function(e){e.preventDefault();});

}

The problem is that after the ajax call, the .on() events doesn´t register. It works with jquery 1.8.0 and olders but in 1.8.1 I get the href from elements fired instead the preventDefault().

Attachments (0)
Change History (7)

Changed September 02, 2012 01:38PM UTC by dmethvin comment:1

owner: → jgleiser
status: newpending

Please provide a test case at jsfiddle.net or jsbin.com.

Changed September 07, 2012 04:07PM UTC by jkane001@gmail.com comment:2

I don't have code I can easily put on jsfiddle, but I can second this - it's not just "on()", either - no click events seem to get handled (by jQuery) after an ajax call.

Changed September 07, 2012 04:11PM UTC by dmethvin comment:3

Great, we'll start looking at that right a...whoops, still no test case. If you can't reduce it, please head over to http://forum.jquery.com or StackOverflow and see if people there can help you figure out whether this is a bug or not.

Changed September 07, 2012 04:17PM UTC by dmethvin comment:4

component: unfiledevent
milestone: None1.8.2
priority: undecidedblocker
status: pendingopen

I'll mark this as blocking 1.8.2 pending investigation but we MUST have more information to help track this down.

Changed September 17, 2012 04:41PM UTC by dmethvin comment:5

resolution: → notabug
status: openclosed

We have not had any additional reports and have not received any test cases, so I'm closing this ticket.

Changed October 01, 2012 07:42AM UTC by loon88@live.com comment:6

i do have the same issue when using 1.8.1, the e.preventDefault() just doesn't work in dynamic generated contents. i am using .on(). but it works in 1.8.2.

Changed October 01, 2012 12:21PM UTC by mikesherov comment:7

Please provide a test case that demonstrates this issue if you are still experiencing one. Thanks!