Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put var inside jquery :gt()

I have a list set with display:none and some code to show item 3:

HTML:

<ul>
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
    <li>item 4</li>
</ul>

jquery:

var item = '1';

$("li:gt(1):lt(1)").show();

Is it possible to get the var inside the gt selection? Al I can think of is this

$("li:gt('+item+'):lt(1)").show();

Doesn't work. Can this be done? If not what else can I try?

Example: http://jsfiddle.net/BSakQ/5/

like image 644
Youss Avatar asked Feb 05 '13 09:02

Youss


1 Answers

You need to delimit the string with the correct quotes. Try this:

$("li:gt(" + item + "):lt(1)").show();
like image 198
Rory McCrossan Avatar answered Oct 11 '22 05:10

Rory McCrossan