Response title
This is preview!
I'm new using JavaScript, and I'm trying to append the Google Plus "Share" button to each individual blog post on my blog's index page. To that end, I'm using the JavaScript code below.
In theory, this should extract the main URL of my page and each <a.blog-title-link
's> (href). However, the link appearing on the google share button is the same for every post. For each blog post sharing link, I get this: /3/post/2014/04/this-is-6post.html
.Help? Fiddle Example
<body> <div class='blog-index-page'> <div class='blog-post'> <div class='blog-header'> <h2 class='blog-title'> <a href='/3/post/2014/04/this-is-6post.html' class='blog-title-link' class='blog-link'>THIS IS POST 6</a> </h2> </div> </div> <div class='blog-post'> <div class='blog-header'> <h2 class='blog-title'> <a href='/3/post/2014/04/this-is-5post.html' class='blog-title-link' class='blog-link'>THIS IS 5 POST</a> </h2> </div> </div> <div class='blog-post'> <div class='blog-header'> <h2 class='blog-title'> <a href='/3/post/2014/04/this-is-4post.html' class='blog-title-link' class='blog-link'>THIS IS 4POST</a></h2> </div> </div> </div> var uri = $('a.blog-title-link').attr('href'); var res = (uri); $('div.blog-post').each(function(){ $(this).append('<a href="https://plus.google.com/share?url='+(window.location.origin)+''+(uri)+'">shareplus</a>'); } ); </body>
© 2013 jQuery Foundation
Sponsored by and others.