Reputation: 545
what i am trying to do is sharing a label text value as url link on twitter but its not working as expected. whats wrong with my code ..
my label value is generated from db:
<asp:Label ID="lblReferralURL" runat="server" Text="" ForeColor="Blue" Font-Bold="true"></asp:Label>
<a href="https://twitter.com/intent/tweet?url=https://google.com" id="TwitterLink" class="twitter" onclick="window.open(this.href, 'mywin','left=300,top=100,width=650,height=500,toolbar=1,resizable=0'); return false;">Tweet New</a>
$(document).ready(function () {
var para = $('#cphPage_lblReferralURL').html();
$('#TwitterLink').attr('href', function () {
return this.href + '?url=' + para;
});
});
Upvotes: 0
Views: 330
Reputation: 943
Try this. Change http://www.example.com/ with your url and New Text with your text.
$(document).ready(function(){
$("#TwitterLink").attr("href", "http://www.example.com/");
$("#TwitterLink").html("New Text");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="https://twitter.com/intent/tweet?url=https://google.com" id="TwitterLink" class="twitter" onclick="window.open(this.href, 'mywin','left=300,top=100,width=650,height=500,toolbar=1,resizable=0'); return false;">Tweet New</a>
Upvotes: 0
Reputation: 581
Your Id is wrong change this line into:
var para = $('#lblReferralURL').textContent;
Upvotes: 1