/ Published in: jQuery

Making a box clickable. It uses the first link from the box as a location for the click event. In this case, it also toggles a hover-class for visual puposes.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
HTML: <div class="clickable"> <h2>Item title</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lacinia semper molestie...<p> <a href="#">Read more</a> </div> JS: $(".clickable") .click(function(){ location = $(this).find("a:first").attr("href"); }) .mouseover(function(){ $(this).toggleClass("hover"); }) .mouseout(function(){ $(this).toggleClass("hover"); });
Comments
