I am using Sharepoint Designer and the HTML is generated automatically. The way it works now is that only the tag is clickable and the div around it is not.
<ul class="dfwp-list">
<li>
<div class="item" style="cursor: pointer;">
<div class="image-area-left">
<a href="/Agencies/accounting/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/file-invoice-dollar.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/accounting/Pages/default.aspx" title="Accounting Division">Accounting
Division</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item" style="cursor: pointer;">
<div class="image-area-left">
<a href="/Agencies/air/Pages/default.aspx"><img class="image" src="/Agencies/PublishingImages/wind.svg"
title=""></a>
</div>
<div class="link-item"><a href="/Agencies/air/Pages/default.aspx" title="Air Quality Program">Air Quality
Program</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/aviation/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/plane-departure.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/aviation/Pages/default.aspx" title="Aviation Department">Aviation
Department</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item" style="cursor: pointer;">
<div class="image-area-left">
<a href="/Agencies/healthcare/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/building.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/healthcare/Pages/default.aspx"
title="Broward Addiction & Recovery Center">Broward Addiction & Recovery Center</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/budget"><img class="image" src="/Agencies/PublishingImages/money-bill-alt.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/budget" title="Budget & Management">Budget & Management</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/callcenter/Pages/default.aspx"><img class="image" src="/Agencies/PublishingImages/phone.svg"
title=""></a>
</div>
<div class="link-item"><a href="/Agencies/callcenter/Pages/default.aspx" title="Call Center">Call Center</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/construction/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/toolbox.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/construction/Pages/default.aspx"
title="Construction Management Division">Construction Management Division</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/administrator/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/folder-open.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/administrator/Pages/default.aspx"
title="County Administrator's Office">County Administrator's Office</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/econdev/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/chart-area.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/econdev/Pages/default.aspx"
title="Economic & Small Business Dev.">Economic & Small Business Dev.</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/eldervets/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/handshake.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/eldervets/Pages/default.aspx"
title="Elderly & Veteran's Services Division">Elderly & Veteran's Services Division</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/EmergencyManagement/Pages/default.aspx"><img class="image"
src="/Agencies/PublishingImages/ambulance.svg" title=""></a>
</div>
<div class="link-item"><a href="/Agencies/EmergencyManagement/Pages/default.aspx"
title="Emergency Management">Emergency Management</a>
<div class="description"></div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="image-area-left">
<a href="/Agencies/EAP/Pages/default.aspx"><img class="image" src="/Agencies/PublishingImages/user.svg"
title=""></a>
</div>
<div class="link-item"><a href="/Agencies/EAP/Pages/default.aspx" title="Employee Assistance Program">Employee
Assistance Program</a>
<div class="description"></div>
</div>
</div>
</li>
</ul>
I am creating a code that gets the href of the clicked element and directs the user to the page on click. But what happens is that when I click it sends me to the same page instead of the url that belongs to the clicked event.
$(".item").hover(function(){
$(this).css('cursor', 'pointer');
});
$(".item").click(function(event) {
var href = $('.item a').attr('href');
window.location = href;
event.preventDefault();
});
var href = $('.item a').attr('href');, tryvar href = $('.item div a').attr('href');window.location = href;towindow.location.href = hrefevent.preventDefault();as the first line inside the function - like this:$(".item").click(function(event) { event.preventDefault(); var href = $('.item a').attr('href'); window.location = href; });