0

我知道这可能很容易做到,但是假设我有这样的事情:

 $(document).on('click', 'a.my_link', function(){

       var my_anchor_object = $(this)     

 });

如何获得实际的锚字符串:

<a href="test.com" id="my_link_id" class="my_link_class">My Link</a>

我的链接(不是 jQuery 对象)来自my_anchor_object

谢谢

4

2 回答 2

5

Try like

var my_anchor_object = $(this).attr('href');     

and you can use this href for your anchor tag.If you want an entire tag try like

var my_anchor_ref = $(this).attr('href');
var my_anchor_txt = $(this).text();   
//Now append to a div
$('#my_div_id').append('<a href="'+my_anchor_ref+'">'+my_anchor_txt+'</a>');

Haha simply try with

var my_anchor = $(this).get(0);
$('#my_div_id').append(my_anchor);   
于 2013-05-29T04:47:14.690 回答
1

使用下面的代码

$(document).on('click', 'a.my_link', function(){
   var my_anchor_object = $(this).clone().wrap('<div/>').parent().html();
    alert(my_anchor_object);
});

检查http://jsfiddle.net/Pyk4Y/25/

于 2013-05-29T04:56:20.197 回答