Reputation: 41
Thanks in advance for any help. I am using the following code to make an entire li "Clickable". The problem is, if you click on any of the actual text other than the link itself (red, blue & green stats), it returns "undefined". See live link here: http://174.122.31.60/.
$(".available-properties li").click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
Upvotes: 1
Views: 946
Reputation: 710
You'll get a race condition if you don't filter out the 'a':
$('.available-properties li').click(
function(e) {
if(!($(e.target).is('a'))) {
window.location = $(this).children("a:first").attr("href");
}
}
);
Upvotes: 0
Reputation: 35983
Try this code:
$(".available-properties li").click(function(){
window.location=$(this).parent().parent().find("a").attr("href");
return false;
});
Upvotes: 1
Reputation: 208040
Just change this:
$(".available-properties li").click
to this:
$(".available-properties > li").click
This way you only select the child LI of the available-properties UL element.
Upvotes: 0
Reputation: 296
This will work. With > the click function will work only on the parent and not the li in the child ul.
$(".available-properties > li").click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
Upvotes: 0