How can I make the Share This button to share the link it stays beside?
so is this Share This button which is doing a pretty good job except the fact that is not sharing the link is staying beside but the link of the page is staying on.
e.g. StackOverflow Link
SHARE THIS button.
question: how can I开发者_如何转开发 make this button to share the link it stays beside, in this case, to share the StackOverflow Link?
I'm pretty much a newbie in JS so if someone can share the entire working code here will be appreciated :)
Thanks folks :) VD
Assuming your link is an anchor (<a... />
) and your button is a button (<input type="button" />
) you can wrap them both in a container and do something like this:
<div>
<a href="http://www.stackoverflow.com/">link</a>
<input type="button" value="share link" />
</div>
$(document).ready(function() {
$('input:button').click(function() {
var url = $(this).parent().find('a').attr('href');
// do something to share url.
});
});
Example: http://jsfiddle.net/fallen888/PaJLT/2/
精彩评论