How to make clickable blocks (using jquery)

13.06.2011
1680x1050_piranha

An article to help a good coder. Every good layout designer knows that the <a> tag is an inline element, only an inline element can be put inside it, but often in the design layout it is necessary to make the blocks clickable (for example, "block with news annotations").

What is the way out of this situation?

  • Include a bunch of blocks in the <a> tag and make the layout not valid (very bad way).
  • Use jquery (+ understandable html structure, valid code).
  • HTML
    
    <div class="post">
         <a href="#">News title</a>
         <p>some annotation text, some annotation text.</p>
    </div>
    
    JQUERY
    $(document).ready(function(){
        $('.post').click(function(){
            window.location=$(this).find('a').attr('href');
            return false;
        })
    });
    

    PS And the fish here means that "You can't even catch a fish from a pond without labor)"

    Last in our blog

    Internet Marketing
    04.11.2019