Fernando Prieto
Fernando Prieto

Reputation: 520

JQuery selector not working on firefox

I have a problem with this jquery selector in Firefox but in Chrome works OK. I'm attaching this event handler after an ajax call. I also tried with live() insted of on() but the same happened... it worked fine in Chrome but not in Firefox. The firefox version is 24.0.

Here is my code:

$("#paginationlinks > li > a").on("click",function(){
    alert("hello world");});

Upvotes: 0

Views: 2322

Answers (2)

dougmacklin
dougmacklin

Reputation: 2610

Firefox requires clicks to have an argument for what is getting clicked on if you want to reference it later (like you would with .preventDefault):

$("#paginationlinks > li > a").on("click",function(event){
    event.preventDefault;
    alert("hello world");
});

Notice the event in function(event)

Fiddle working in Firefox: http://jsfiddle.net/hCE6h/

Fiddle not working in Firefox: http://jsfiddle.net/hCE6h/1/

Chrome doesn't care either way.

Upvotes: 1

Patrick Moore
Patrick Moore

Reputation: 13344

You might try this by using children() selector and use of on()'s second parameter to specify a selector (rather than using > to specify direct descendants):

$("#paginationlinks").children("li").on("click", "a", function(){
    alert("hello world");
});

http://api.jquery.com/on/

Upvotes: 0

Related Questions