What is the difference between $(this) and this

前端 未结 5 1773
北海茫月
北海茫月 2020-12-20 21:18

I have the following code

$(\'a\').click(function() {
var url= this.href;
alert(url);
});

This works just fine and sure enough the returned

5条回答
  •  悲&欢浪女
    2020-12-20 21:34

    Lots of good answers, just wanted to add that you could also do this:

    $('a').click(function(e) {
        alert($(this)[0].href);
    });
    

提交回复
热议问题