Alright this is just something I figured that might be useful to help people out in javascript a lot.
Ever see code like….
var targ = e.target?e.target:e.srcElement;
Generally the question that comes to mind what the heck is that quesiton mark for? Belive it or not it’s a short hand If statement.
Basically in this case it’s like saying if e.target exist then set variable targ to e.target. If not, “ELSE”, make targ equal to e.srcElement. This is really useful for cross browser issues.
Sadly, you can’t really use it in the AJAX code all that easily. Due to how many conditions you have to test against. But it’s really useful for other issues.
Also to clear some things up:
a=(a==b)?c:d
You can also write it out like that to mean… if a = b then set to c if NOT set to d.
Well hopes that helps you guys some. Also once I finish up on this drag element script I’ll be sure to update you with a really neat cross browser script for creating a draggable inbound window. Of course we’ll see how long it takes with my busy schedule.
Thanks for the info……ive been wondering for a while what that was…….
Comment by Michael — December 3, 2008 @ 11:29 am
Thanks dude, this came up on a script and I was like…what the hell???
Comment by Camilo — April 30, 2009 @ 7:10 am
I was hoping it’d be something magical.
Comment by murrietadesign — November 3, 2009 @ 7:46 am
One of the idiotic syntax part of JavaScript – badly readable!
Tx for explanation!
These JS developers were true idiots!
Comment by Frank — December 13, 2009 @ 2:06 pm