最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing data-url or similar attributes on Element - Stack Overflow

programmeradmin2浏览0评论

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.

Share Improve this question asked Mar 22, 2012 at 17:27 Codex73Codex73 5,77613 gold badges58 silver badges77 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You 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/

发布评论

评论列表(0)

  1. 暂无评论