Reputation:
I'm looking for a way to redirect a page based on a div's a href link. If there is only one div on the page, then redirect to the a href link for that div.
JS
$(function () {
if ($('.div').length = 1) { alert('Just one Div'); }
});
HTML
<div class="div"><div class="title"><a href="../posters/bicycles/default.html">Bicycle</a></div>
Upvotes: 1
Views: 552
Reputation: 49949
you can do this, returns the number of DIV elements:
if( $("div").length == 1 )
{
document.location = $("div a").attr("href");
}
Upvotes: 1
Reputation: 73966
Try this:
$('.div a').click(function (e) {
e.preventDefault();
window.location.href = $(this).attr('href');
});
Upvotes: 1