I am trying to change the href value from within a getJSON call. The following works outside the call but not inside. Any ideas?
$("#tweetButton").prop("href", "https://twitter.com/intent/tweet?text=test&url=%20&hashtags=quotes");
HTML:
<div id="quote">
<div id="quoteText">
Test
</div>
</br>
<a id="tweetButton" href="https://twitter.com/intent/tweet?text=&url=%20&hashtags=quotes" class="twitter-share-button">Tweet</a>
<button id="btnNewQuote">New Quote</button>
</div>
jQuery:
$(document).ready(function() {
$.ajaxSetup({ cache: false });
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=", function(a) {
$("#tweetButton").prop("href", "https://twitter.com/intent/tweet?text=test&url=%20&hashtags=quotes");
$("#quoteText").html(a[0].content + "<p>— " + a[0].title + "</p>");
// $("#tweetButton").attr("href", "https://twitter.com/intent/tweet?text=" + encodeURI(a[0].content) + encodeURI(" -") + a[0].title + "&url=%20&hashtags=quotes");
});
$("#btnNewQuote").click(function(){
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=", function(a) {
$("#quoteText").html(a[0].content + "<p>— " + a[0].title + "</p>");
$("#tweetButton").prop("href", "https://twitter.com/intent/tweet?text=test&url=%20&hashtags=quotes");
});
});
});