JQuery&子选择器A>B: 不工作?[Chrome 24,JQmobile]

JQuery & Child selector A > B: not working ? [Chrome 24, JQmobile]

本文关键字:Chrome JQmobile 工作 选择器 amp gt JQuery      更新时间:2023-09-26

给定嵌套的html:

<a class="star">Hello world!
 <a class="ui-icon-star"> hello </a>
</a>

我使用了以下JS:

$('.star').click(function () {
    $(this).toggleClass("favorited");
    $(this > '.ui-icon-star').toggleClass("ui-icon-starred");
});

更改.star和child.ui图标的star元素,但它不适用于child。我的[选择器(?)]错误在哪里?大约$(这个>.ui图标星)。

1:http://jsfiddle.net/tNwND/1/2:http://www.w3.org/TR/CSS21/selector.html

这是因为您的标记无效,浏览器以这种方式呈现您的标记:

<a class="star">Hello world! </a>
<a class="ui-icon-star"> hello </a>

因此,单击的元素没有.ui-icon-star子元素。