开发者

li clickable but with rel - jquery

开发者 https://www.devze.com 2023-04-13 00:36 出处:网络
I\'m using jQuery prettyPhoto to display an overlay window. On my page I have an li with a link and image, I want the whole li to be clickable BUT the link is #, so it\'s rel doing the work.

I'm using jQuery prettyPhoto to display an overlay window.

On my page I have an li with a link and image, I want the whole li to be clickable BUT the link is #, so it's rel doing the work.

<a href="#inline-'.$i.'" rel="prettyPhoto[inline]">'.preg_replace($patterns,$replacements,$vimeo->title).'</a>

Below is my jQuery, any ideas?

$(function() {
    $('.clickable').css('cursor', 'pointer').click(function() {
 开发者_运维问答       window.location = $(this).find("a").attr("href") + $(this).find("a").attr("rel");
        return false;
    });
});


I recommend against trying to make the <li> clickable. If you can't wrap some element (like an <li> or a <td>) in an anchor, you can make the anchor fill the whole area of the element with CSS: example on jsFiddle. (You can probably find less rough ways to do that on ALA or such.) Then just intercept the click event on the link.

Also, as Quentin said, don't repurpose rel or other attributes; you can use data attributes as a "clean" alternative.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号