Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

jquery - Select "div class" from ajax response

I′ve the following ajax-response which is generated by my server-sided script:

<div class="item-title3">Testname</div>
<div class="item-level">120</div>
<div class="item-binding">40</div>
<div class="item-type">Feet</div>

Now I want to find the content of the <div class="item-title3"> ("Testname" in that case) and use it as a link name.

Therefore I turned the ajax data into a jQuery object to select certain elements from it. Sadly it still can′t find it.

Complete code:

<script language="javascript">

jQuery(function($) {
  
  $("[tooltip-link]").each(function() {
    let $tooltip = $(this);
    let id = $tooltip.attr("data-id");

    $.ajax({ 
      url: "/datenbank/itemscript.php",
      type: "GET",
      data: {
        "var": id
      }
    }).then(function(data) {
      let $content = $(data);
      let title = $content.find('.item-title3').text()

      $tooltip.tooltip({
        tooltipClass: "test",
        content: data
      });

       $("<div class="item-title">Item-" + title + "</div>").appendTo($tooltip);
    });
  });
    
});
</script>

<a tooltip-link data-id="12555" title=""></a>
question from:https://stackoverflow.com/questions/65885366/select-div-class-from-ajax-response

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...