admin管理员组文章数量:1322838
I'm trying to access the data-url attribute of the following element so it could be replaced upon callback or as needed with jQuery / Javascript.
What method will work to do this?
<a id="twitter_link" href="" class="twitter-share-button" data-via="imdto" data-lang="en" data-url="">Tweet</a>
I've tried using attr()
, prop()
functions but returns undefined.
I'm trying to access the data-url attribute of the following element so it could be replaced upon callback or as needed with jQuery / Javascript.
What method will work to do this?
<a id="twitter_link" href="https://twitter./share" class="twitter-share-button" data-via="imdto" data-lang="en" data-url="http://mydomain./changeme">Tweet</a>
I've tried using attr()
, prop()
functions but returns undefined.
3 Answers
Reset to default 3You need to use the data function (for example):
$(myElement).data('url')
What version of jQuery are you using? In the latest version, it works like so:
$("#twitter_link").attr( "data-url" );
Awesome example! http://jsfiddle/shanabus/taGBL/1/
try to read the attribute with $('#twitter_link').data('url');
About jQuery data()
method: http://api.jquery./jQuery.data/
本文标签: javascriptChanging dataurl or similar attributes on ElementStack Overflow
版权声明:本文标题:javascript - Changing data-url or similar attributes on Element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742116231a2421479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论