I have this HTML:
<div class="divHolder">
<a href="./"><img src="./images/image6.jpg"/></a>
</div>
<div class="divHolder">
<a href="./IT.aspx"><img src="./images/image7.jpg"/></a>
</div>
In my JavaScript I have:
$('.divHolder').click(function () {
var link = $(this).find("a").attr("href");
if (link != null) {
location.href = link;
}
});
However, every time I click on a div, the href of the div is always the last one: for example in this case is: IT.aspx.
What did I do wrong?
linkis of course nevernull. Have you triedalertinglinkrather than immediately forwarding to it? I'm just wondering whether it's just that the default page, if that's the correct term, isIT.aspxand essentially in the first instance all you're doing is stripping the url down to the last directory which will then load the default page in that directory.