开发者

Why is the onclick event not firering on my anchor with an image inside it?

开发者 https://www.devze.com 2023-04-11 18:44 出处:网络
I\'m working on copy to clipboard using the zeroclipboard api,. I made a simple test page with an HTML anchor as follows:

I'm working on copy to clipboard using the zeroclipboard api,. I made a simple test page with an HTML anchor as follows:

<a href="#" id="copy" >copy</a>

By clicking on copy link, the text is co开发者_高级运维pied to clipboard, all js events are firing and are being logged properly into the console, but when I change the example above to have an image inside the anchor for better user experience:

<a href="#" id="copy" ><img src="copy.gif" alt="copy"/></a>

...the code does no longer work and no events are fired.


Set the image as the background image of the a element using CSS.

#copy {
    background-image: url('copy.jpg')
    display: block
    width: XXXpx
    height: YYYpx
}

You can use display: inline-block if you want the a element to behave more like a span.

0

精彩评论

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

关注公众号