Prevent Default Action

JavaScript related questions should go here.
Post Reply
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Prevent Default Action

Post by unemployment »

I am loading a link with ajax. When the link pops on the screen and I click it, I get redirected to my 404 page and my lightbox doesn't load.

If the link pops in and I refresh my browser, then I click the link my lightbox will show up.

How can I do a prevent default on the <a href> in pure JS? No frameworks please.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Prevent Default

Post by jacek »

unemployment wrote:in pure JS? No frameworks please.

:D :D :D :D

You need to have the function that does the lightbox or what ever it is that happens when you click the link return false. that should stop the default action.
Image
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Re: Prevent Default Action

Post by unemployment »

Fixed. As it turns out... it wasn't even a return false issue. JavaScript can be very tricky sometimes.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Prevent Default Action

Post by jacek »

what did you do ?
Image
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Re: Prevent Default Action

Post by unemployment »

jacek wrote:what did you do ?


I wasn't calling the light box. The Ajax was pulling in a dead link and the JavaScript referenced the hard coded HTML link so when the Ajax overrode the hard coded link that JavaScript wasn't referencing the Ajax link. It was basically due to not properly calling the light box in the Ajax request.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Prevent Default Action

Post by jacek »

hmm, fair enough ;)

As long as its working eh :D
Image
Post Reply