Recently in Javascript Category

February 14, 2008

Sad, funny and true web dev story

I asked a MySpace developer why a few particular links on their site were javascript onclick events applied to a span tag, rather than anchor tags.

He said it was because the product specifications required those links not to be underlined.

*headdesk*

This explains a lot.

December 19, 2006

Peter's image hover question

Peter was trying to make a border appear around his images when the user hovered over them. His solution was to put anchors around his images so he could use the a and a:hover CSS classes to define border styles for the hover states.

Unfortunately, he didn't want the page to reload or change its position when the image was clicked. Without the href property, the hover states did not work in IE, but with # in the href property, the page would jump back to the top.

There was a bug with using javascript to change the CSS class of image because the DOM element was dynamically generated, so using javascript to change the className was not a viable option.

In the end, Peter came up with a hack to do the trick.


(4:44:50 PM) Peter Chang: you can do something like this
(4:45:11 PM) Peter Chang: <a href="doVoid()" onclick="myFunction(); return false" ...
(4:45:26 PM) Peter Chang: the href doesnt' go anywhere.. i thin because you rturn false on click
(4:45:39 PM) winonatong: i didn't know you could put javascript in the href
(4:45:41 PM) Peter Chang: i'm not even sure if it execs dovoid
(4:45:44 PM) Peter Chang: i know!
(4:45:59 PM) winonatong: that's a nifty hack
(4:46:29 PM) Peter Chang: actually you can have just junk in the href
(4:46:38 PM) Peter Chang: i guess the return false prevents the forwarding