Digbyswift is based in Leeds, West Yorkshire offering web and digital solutions. With over a decade of experience in corporate and agency web development, Digbyswift can meet and support your requirements, whether it be MVC or web forms development, Umbraco, bespoke CMS build and maintenance, ecommerce, SEO and Google analytics or even client training. Read more ...

Amused Bush

By Digbyswift at March 25, 2011 13:15

Some people were just made for writing their thoughts down. A friend, Bushy aka Bushington aka Andrew is one of these people. He has his own blog over at Amused Bush and he writes like I would like to be able to write.

He’s a wordsmith, a copywriter and has ghost written a book on integrated marketing amongst many other things.

Check his blog out. Learn something new. Discover how to construct nipple tassels.

Clickable panels using jQuery

By Digbyswift at February 08, 2011 08:28

One thing I’m always in need of is to make a block element of a web page clickable. For example, the block may be a DIV element containing an image, heading and summary text. It may be a table row, a list element, search result or a point of sale.

The way I would need the element to behave is, once clicked, to navigate the user to the URL specified in the first anchor within the panel.

I use the following code to achieve this:

$(document).ready(function() {

    SetPanelLinks();

});

function SetPanelLinks() {

    $('.linkpanel')
        .click(function() {
            var link = $(this).find("a").eq(0);
            location.href = link.attr("href");
        })
}

This of course relies upon me placing a “linkpanel” class on each element I require to inherit this functionality.

I can further extend this by allowing for a rollover state:

function SetPanelLinks() {

    $('.linkpanel')
        .click(function() {
            var link = $(this).find("a").eq(0);
            location.href = link.attr("href");
        })
        .mouseover(function() {
            $(this).css("cursor", "pointer");
            $(this).toggleClass("linkpanel_hover", true);
        })
        .mouseout(function() {
            $(this).css("cursor", "default");
            $(this).toggleClass("linkpanel_hover", false);
        });
}

I’m absolutely sure this is far from perfect – for example, there is no target consideration. But it does the job nicely.