当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Pinterest button is not catching 'Click' event

问题描述:

This is the code for a simple pinterest button.

<div class="myPinterestButton">

<a href="//www.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest"

data-pin-do="buttonPin"

data-pin-config="none">

<img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" />

</a>

</div>

<script type="text/javascript" async src="//assets.pinterest.com/js/pinit.js"></script>

None of the content is iframed. The pinterest button ends up being the <a> tag with some additional data attributes (thanks to the pinit.js which adds it at runtime).

Here's the thing I don't undrestand. If I click the button it works fine. But if I want to trigger a click on it (for example click a different element on the page and use jQuery to do $(".myPinterestButton a").trigger("click") it doesn't work.

Here's a jsfiddle: http://jsfiddle.net/h42vK/2/

What's going on here please?

网友答案:

You can use click event for wrapper div .myPinterestButton instead .myPinterestButton a

$(".myPinterestButton").trigger("click")
分享给朋友:
您可能感兴趣的文章:
随机阅读: