Assign the child's href to the parent's onclick
This is a cool little snippet for making realistic CSS buttons. It will do an onclick location on the element to the href of its first a element.
Makes it nice when you have a "fake button" done through CSS and you want the whole thing to be clickable.
What I usually try to do is CSS the A tag display:block and assign it a width, height and padding, but when you can't do that, this little snippet is a life saver
onclick="if (this.getElementsByTagName('a')[0])
location=this.getElementsByTagName('a')[0].href;"
Labels: All, CSS, Javascript
1 Comments:
Tom,
Very useful! A little note, I had to do it this way: onclick="if (this.getElementsByTagName('a')[0])
{location=this.getElementsByTagName('a')[0].href};" in order for it to work. Thanks, for the help.
Post a Comment
<< Home