Archive for the ‘Html/Css’ Category

Programmatically clicking an anchor tag via Javascript

Here’s a simple one that occurs often. Take for instance, the links on the sidebar of this blog. The links are wrapped in list items, however you’ll notice that you can just as easily click the big list item block as you can the link itself. Additionally, hovering over the list item triggers the hover state of the child link element. Here’s the code used to achieve this.

// Cause the parent list item to function like its child link
// Note we must use window.location as triggering a click event programmatically will not work!
$('li.widget_categories li, li.widget_archives li').click(function() {
    window.location = $(this).children('a').attr('href');
});

// When mousing over a list item, we add a class to the child link that imitates its hoverstate.
// Triggering mouse events and the like will only cause recursion errors.
$('li.widget_categories li, li.widget_archives li').mouseenter(function() {
    $(this).children('a').addClass('active');
});

// Same as above, only this time we return to normal
$('li.widget_categories li, li.widget_archives li').mouseleave(function() {
    $(this).children('a').removeClass('active');
});

Simple stuff here, but that’s about all I seem to ever have time to write down.

How many H1 tags per page? One per page

I recently searched for the answer to the question of how and why do you use H1 tags on a page. I’ve long understood that you only use one single H1 tag per page, but I was surprised that even google’s top result for the query doesn’t actually use the H1 anywhere on the page.

For simplicity sake on this blog, I use an H1 tag at the top for my name and H2 tags for posts. On single post pages and content pages, the H1 tag is used for their title and my name switches to an H2 (I rank for Austin Marron no matter what). More