在 slice().hide() 函数中组合两个选择器 - jQuery

Combine two selectors in slice().hide() function - jQuery

如何将其合并为一个声明?这些元素没有 ID 或唯一名称,只是选择器本身。

$("article").slice(1).hide();
$("main h1").slice(1).hide();

* 编辑 *

GaetanoM 的回答有效...

$('article:gt(0), main h1:gt(0)').hide()

我尝试了类似于 Matiboux 建议的方法(以及 he/she 的建议,显然)...

$("article, main h1").slice(1).hide();

跟进问题 - 谁能解释为什么第二个问题不起作用?似乎更直接。它完全隐藏了文章。

我认为 $("article, main h1").slice(1).hide(); 应该可以解决问题。这类似于 CSS 规则。

你可以combine selectors using :gt() Selector and remembering that .slice( start )表示:

Reduce the set of matched elements to a subset specified by a range of indices. the parameter is an integer indicating the 0-based position.

代码段是:

$('article:gt(0), main h1:gt(0)').hide()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



<article>
    articol 1
</article>
<article>
    articol 2
</article>
<article>
    articol 3
</article>


<main>
    <h1>h1</h1>
</main>
<main>
    <h1>h2</h1>
</main>
<main>
    <h1>h3</h1>
</main>