kritya
kritya

Reputation: 3362

jQuery limit the number of elements shown to say like 5

I got lets say this:

<ol>
<li>Content1</li>
    <li>Content2</li>
    <li>Content3</li>
    <li>Content4</li>
    <li>Content5</li>
    <li>Content6</li>
    <li>Content7</li>
    <li>Content8</li>
    <li>Content9</li>
    <li>Content10</li>
    <li>Content11</li>
    <li>Content12</li>
    <li>Content13</li>
</ol>

And the js something like this :

$("li").hide()
$("li:contains('Content')").show()

Qusetion :

Now How can i limit the number of shown elements to lets say around 5 ?

Upvotes: 3

Views: 4607

Answers (2)

Vivek
Vivek

Reputation: 11028

try this-

$("ol li:contains('Content'):lt(5)").show();

Upvotes: 1

karim79
karim79

Reputation: 342635

$("ol li:contains('Content')").slice(0, 5).show();

or:

$("ol li:contains('Content'):lt(5)").show();

Upvotes: 10

Related Questions