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/