I figured out how to do this in css :
.dl-menuwrapper li > a(:only-child)
But I don't manage to make this work in a jQuery selector :
$(document).on('click', '.dl-menuwrapper li a(:only-child)', function () {console.log('it works');});
I don't get what I am missing here and a little help would be much appreciated.
答案 0 :(得分:2)
您输入了两个额外的括号。
正确的版本:
$(document).on('click', '.dl-menuwrapper li a:only-child', function () {console.log('it works');});
你的css会是这样的:
.dl-menuwrapper li > a:only-child{
/* some styles */
}
答案 1 :(得分:1)
为什么在()
周围使用:only-child
。像下面一样删除它。
<强> CSS 强>
.dl-menuwrapper li > a:only-child
<强>的jQuery 强>
$(document).on('click', '.dl-menuwrapper li a:only-child', function () {
console.log('it works');
});