How to change the href for a hyperlink using jQuery

前端 未结 12 2128
孤街浪徒
孤街浪徒 2020-11-21 11:15

How can you change the href for a hyperlink using jQuery?

12条回答
  •  执笔经年
    2020-11-21 11:55

    This snippet invokes when a link of class 'menu_link' is clicked, and shows the text and url of the link. The return false prevents the link from being followed.

    Option 1
    Option 2
    
    $('.menu_link').live('click', function() {
       var thelink = $(this);
       alert ( thelink.html() );
       alert ( thelink.attr('href') );
       alert ( thelink.attr('rel') );
    
       return false;
    });
    

提交回复
热议问题