Get href attribute on jQuery

后端 未结 6 1415
眼角桃花
眼角桃花 2021-02-12 13:24

I have some table rows


    
        
      
6条回答
  •  南方客
    南方客 (楼主)
    2021-02-12 14:09

    var a_href = $('div.cpt').find('h2 a').attr('href');
    

    should be

    var a_href = $(this).find('div.cpt').find('h2 a').attr('href');
    

    In the first line, your query searches the entire document. In the second, the query starts from your tr element and only gets the element underneath it. (You can combine the finds if you like, I left them separate to illustrate the point.)

提交回复
热议问题