how can i get the text inside an anchor tag in jquery

前端 未结 2 709
醉话见心
醉话见心 2021-01-13 21:13


//jquery
$(\"#div1 a\").click(function(){
var text = $(         


        
相关标签:
2条回答
  • 2021-01-13 21:13

    Inside the click handler, this refers to the element which triggered the handler execution :

    $("#div1 a").click(function(){
        var text = $(this).text();
    });
    
    0 讨论(0)
  • 2021-01-13 21:20

    Use this :

      $("#div1 a").click(function(){
        var text = $(this).text();
      });
    
    0 讨论(0)
提交回复
热议问题