DOJO 查询伪元素

DOJO query pseudo elements

我有一个 DOM 对象 item,我希望使用 DOJO 的查询选择器查询 DOM 对象的 ::after 伪元素。

我试过了

    _getExpandableIcon: function(item) {
        return query(item + '::after')[0];
    },

    _getExpandableIcon: function(item) {
        return query('::after', item)[0];
    },

我的 dom 对象看起来像

<li class="sos-side-navigation-item expandable">
    <div class="sos-side-navigation-item-icon">
        <span class="sos-icon sos-icon-currency-gbp"></span>
    </div>
    <div class="sos-side-navigation-item-name">
        Type Something
    </div>
    ::after
</li>

dojo 中的默认选择器引擎不支持伪选择器。

.class, #id, tag, and *, attribute selectors, and child (>), descendant (space), and union (,) combinators. If the native selector engine is, the engine does not support pseudo classes. Ref.

但是你可以更改选择器引擎,例如,你可以使用 sizzle:

<script data-dojo-config="selectorEngine: 'sizzle/sizzle'" src="dojo/dojo.js">
</script>

define(["dojo/query!slick/Source/slick"], function(query){
  query(".someClass:custom-pseudo").style("color", "red");
});