Make clickable div with jQuery according to tag "a href"

The task is to make clickable div tags. There are several div blocks in a page, each div contains a hyperlink with URL. You need to make so, that if you click on div element, you open a hyperlink.

HTML-code of this construction is here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<div id="allitems"> <div class="item"> <div class="vis"></div> <a href="url_1"><span>Link 1</span></a> </div> <div class="item"> <div class="vis"></div> <a href="url_2"><span>Link 2</span></a> </div> <div class="item"> <div class="vis"></div> <a href="url_3"><span>Link 3</span></a> </div> </div> |
The easiest way is to add a small Javascript code if you use jQuery. Of course, it must be added after jQuery loaded.
1 2 3 4 5 6 7 8 9 |
$(function () { $('.item').each(function() { $(this).on('click', function() { var lnk = $(this).find("a").attr('href'); window.location = lnk; }); }); }); |