I have the following ajax response which is generated by a 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 get the div class name
which contains the item-title
word inside of the class name. So the number in the div class name shouldn′t be relevant (in this case the 3 of item-title3 shouldn′t be relevant).
In this example I want to find and store item-title3
inside my variable className.
I tried it with the filter method, but I get [object Object] as a result:
let className = $content.filter('div.item-title');
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.siblings('[class^=item-title]').text()
let className = $content.filter('div.item-title');
$tooltip.tooltip({
tooltipClass: "test",
content: data
});
$("<div class="" + ClassName + "">" + title + "</div>").appendTo($tooltip);
});
});
});
</script>
<a tooltip-link data-id="12555" title=""></a>
question from:
https://stackoverflow.com/questions/65902640/find-div-class-name-from-ajax-content 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…