Javascript 如何选择$(this)JQuery选择器选择的元素中的第一个div?

Javascript 如何选择$(this)JQuery选择器选择的元素中的第一个div?,javascript,jquery,html,dom,jquery-selectors,Javascript,Jquery,Html,Dom,Jquery Selectors,在JSP页面中,我有如下内容: <!-- Bottone relativo ai progetti WIFI: --> <a title="WIFI" href="javascript: void(0)" id="showWifi_${item.index}" class="showWifi"> <div class="news_box news_box_01 hvr-underline-from-center " style="margin-right:

在JSP页面中,我有如下内容:

<!-- Bottone relativo ai progetti WIFI: -->
<a title="WIFI" href="javascript: void(0)" id="showWifi_${item.index}" class="showWifi">
    <div class="news_box news_box_01 hvr-underline-from-center " style="margin-right: 50px;"></div>
</a>
最后两行选择a标记中具有showWifi作为类的第一个div。问题是,我必须使用**$(this)元素中表示单击元素的第一个div替换这些行


我如何做这件事?

因为您在
中只有一个div。showWifi
您不需要
首先()


如果您在

中有多个
div
,请尝试以下操作:

$(this).children('div:first').addClass('highLightButton');
$(this).children('div:first').removeClass('highLightButton');

更多信息:

如果所需的div是单击元素的直接后代,也可以使用.children()。
 $(this).find('div').addClass('highLightButton');
$(this).find('div').first().addClass('highLightButton');
$(this).children('div:first').addClass('highLightButton');
$(this).children('div:first').removeClass('highLightButton');