dravpuso44681 2016-08-31 12:34
浏览 90
已采纳

jQuery:禁用锚点并使用相同的href创建一个新锚点

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 &#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>');
  • 写回答

3条回答 默认 最新

  • doushu2699 2016-08-31 12:42
    关注

    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>' );
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题