I'm using a Wordpress plugin for loading Facebook events into a web page. There is a big anchor with an event div in it. I want a small anchor at the bottom of every fb-event div instead.
I need to:
Disable the first anchor without removing it (removing it would also remove the entire div).
Create a new anchor at the bottom of the fb-event div.
Pass the href from the first anchor to the second.
I feel like I'm pretty close but nothing happens, this is my code, first html, then jQuery. Thanks in advance!
<div class='fb-event'>
<a class="fb-event-anchor" href="http://www.facebook.com/event.php?eid=1165884803462190" target="_blank">
<div class="fb-event-desc"><img src=https://scontent.xx.fbcdn.net/t31.0-8/s720x720/13920278_1335410149821833_1686522516711277604_o.jpg />
<div class='fb-event-title'>Spiritueel weekend - Een stapje verder</div>
<div class='fb-event-time'>10 september 2016 · 10:00 -<br>11 september 2016 · 17:00</div>
<div class='fb-event-location'>Balance in Life</div>
<div class='fb-event-description'>Lots
</div>
</div>
</a>
</div>
jQuery:
var fblink = $('.fb-event-anchor').attr('href');
$('.fb-event-anchor').click(function(){
return false; // prevents default action
});
$('.fb-event-description').append('<a class="fb-event-anchor-new" href="' . [fblink] . '"></a>');
Try with below code
$(function () {
$('.fb-event-anchor').on("click", function (e) {
e.preventDefault();
});
var fblink = $('.fb-event-anchor').attr("href");
$( ".fb-event" ).append( '<a class="fb-event-anchor-new" href='+ fblink +'>NEW LINK</a>' );
});
you want to do like this ?
var fblink = $('.fb-event-anchor').attr('href');
$('.fb-event-anchor').click(function () {
return false; // prevents default action
});
$('.fb-event-description').append('<a class="fb-event-anchor-new" href="'+fblink+'">fbanchor</a>');
Both solutions succesfully create a new link but neither makes the first link unclickable. I countered that last part with css:
.fb-event-anchor {
pointer-events: none;
cursor: default;
}
Thanks both, Pratik was first so I'll accept his answer.