第一个孩子无法使用我的选择器 [英] First child does not work with my selector

查看:96
本文介绍了第一个孩子无法使用我的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的js

$('dd:first-child', 'dd:first-child(2)').remove();

考虑我的标记是这样的

<dd>
<br>
<br?
</dd>

为什么不起作用?

推荐答案

这是因为first-child(2)不是函数,因此会出现错误.
应该是:

That is because first-child(2) is not a function so it will give an error.
It should be:

$('dd:first-child, dd:eq(1)').remove();

$('dd:eq(0), dd:eq(1)').remove();

$('dd:nth-child(1), dd:nth-child(2)').remove();

这也可能起作用:

$('dd:lt(2)').remove();

lt选择器

lt(2)

要删除<br>,您可以执行以下操作:

To delete the <br> you can do:

$('dd br:lt(2)').remove();

这篇关于第一个孩子无法使用我的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆