Using selectors and $(this) in Jquery Ajax response

前端 未结 4 1830
暗喜
暗喜 2021-01-15 01:39

I am wondering how I use Jquery selectors within the Ajax response. My site has a feed and each main block has a unique ID, but I dont want to uniquly ID every div thats wit

4条回答
  •  无人及你
    2021-01-15 02:09

    Since the ajax is inside the click handler just do this:

    $(...).click(function(){
          var $this = $(this); //<-- reference variable
          //ajax function...
          function(msg){ 
    
             var container = $this.parent().attr('id');   
             alert (container); //returns undefined
    
          }
    })
    

提交回复
热议问题