如何使用这个获取 div 的选择器

How to get div's selector using this

所以我想通过 JQuery 使用 $(this) 获得 div 的选择器 这该怎么做?会是那样吗? $("...这个")

<div id="divId">
     <span onclick="myFunction()">Some Text</span>
     <span onclick="myFunction()">Some Text</span>
     <span onclick="myFunction()">Some Text</span>
     <span onclick="myFunction()">Some Text</span>
</div>
<script>
myFunction(){
selector im asking for.doSomething();
}

</script>

如果你想获取parent的id:

myFunction(){
  $(this).parent('div').attr('id');
}

如果您需要获取 div 本身,请删除 .attr('id')

myFunction(){
   $(this).parent('div');
}

因为您有 div 的 ID,您可以简单地对 div 执行 $('#divId') 到 select。

试试

$('#divId').click(function(){
$(this).hide();
})