Reputation: 638
I'm trying to make a page that generates a quote when you click a 'quote' button and then you can tweet the quote using the twitter button. Here is a link to the twitter button.
The twitter button allows you to tweet out specific text that you want by altering the 'data-text' attribute.
I would like to use my 'quote' button to generate a quote and at the same time alter the data-text attribute of my twitter button so I can click the twitter button after and tweet out a specific quote.
So far I have this which is part of my click function:
$("a").prop("data-text", quotes[j]);
Where j is an index of the quote array but I can't seem to get it to work.
EDIT: Here is a working demo: http://codepen.io/michaelaharvey/pen/wMzGJR
Upvotes: 0
Views: 69
Reputation: 50326
If you check DOM you will not find any a
tag, but .data,.attr,.prop
will require the element to be present in DOM
Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.
Upvotes: 1
Reputation: 1
'://platform.twitter.com/widgets.js`` loads an
iframeinto
.asdf, removing exisiting
aelement within
.asdf. When attempting to access
aelement within
iframe`
Uncaught SecurityError: Failed to read the 'contentDocument'
property from 'HTMLIFrameElement':
Sandbox access violation: Blocked a frame at
"http://stacksnippets.net" from accessing a frame at
"http://platform.twitter.com".
Both frames are sandboxed and lack the "allow-same-origin" flag.
logged to console
Upvotes: 1
Reputation: 487
Im going to be different and suggest using the jquery data method https://api.jquery.com/data/
$("a").data("text", quotes[j]);
Upvotes: 2
Reputation: 12173
You should be able to use .attr
$("a").attr("data-text", quotes[j]);
Upvotes: 1