2016-08-31 26 views
2

我正在使用Wordpress插件將Facebook事件加載到網頁中。有一個事件div的大錨。我想在每個fb-event div的底部添加一個小錨點。jQuery:禁用錨點並創建一個新的具有相同的href

我需要:

禁用第一錨定,而不移除它(刪除它也將刪除整個DIV)。

在fb-event div的底部創建一個新的錨點。

將href從第一個錨點傳遞到第二個錨點。

我覺得我很接近但沒有任何反應,這是我的代碼,第一個html,然後是jQuery。提前致謝!

<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 &#183; 10:00 -<br>11 september 2016 &#183; 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>'); 

回答

1

嘗試用下面的代碼

$(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>'); 
}); 
1
你想要做這樣的

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>'); 
0

這兩個解決方案都成功創建了一個新的鏈接,但都沒有使第一個鏈接不可點擊。我反對最後一部分與css:

.fb-event-anchor { 
    pointer-events: none; 
    cursor: default; 
} 

謝謝兩個,Pratik是第一個,所以我會接受他的答案。

相關問題