Javascript jQuery在h标记中查找元素。要使用哪个DOM选择器?

Javascript jQuery在h标记中查找元素。要使用哪个DOM选择器?,javascript,jquery,html,Javascript,Jquery,Html,我在h标记中有一个图标: <h4 class="ipro_toggle"><i class="fa fa-chevron-down fa-rotate-270 pull-left toggle_icon"></i>Click Me</h4> 找不到图标。我应该使用什么DOM选择器?有几种方法: $(this).children('.toggle_icon').toggleClass('fa-rotate-270 norotate'); 或 或

我在h标记中有一个图标:

<h4 class="ipro_toggle"><i class="fa fa-chevron-down fa-rotate-270 pull-left toggle_icon"></i>Click Me</h4>

找不到图标。我应该使用什么DOM选择器?

有几种方法:

$(this).children('.toggle_icon').toggleClass('fa-rotate-270 norotate');

您使用的方法(
next
)在此处无效,因为
。toggle_icon
不是单击的
元素的下一个同级元素,而是它的后代。

使用,而不是
。next()


您必须用替换下一个。以获取H标记的后代

$(this).find(".toggle_icon").toggleClass("fa-rotate-270 norotate");

谢谢你清楚的回答。不过,我不明白那些反对票。我很清楚我在问什么,我提供了代码示例。同意+1为了补偿我很好奇,为什么你认为
next
会起作用?你事先看过文件了吗?
$(this).find('.toggle_icon').toggleClass('fa-rotate-270 norotate');
$('.toggle_icon', this).toggleClass('fa-rotate-270 norotate');
$("h4.ipro_toggle").click(function(){
    $(this).find(".toggle_icon").toggleClass("fa-rotate-270 norotate");
});
$(this).find(".toggle_icon").toggleClass("fa-rotate-270 norotate");