javascript - jquery & css target nth li with varaible instead of a number -


i using jquery add class li in ul. code:

$('ul').children('li:eq( '2' )').addclass('active');  

how can replace "2" variable dynamic? code below not work. think syntax issue advice?

var count = 2; $('ul').children('li:eq( 'count' )').addclass('active');  

you need concatenate variable.

$('ul').children('li:eq( ' + count +' )').addclass('active'); 

however can use $.fn.eq()

reduce set of matched elements 1 @ specified index.

 $('ul').children('li').eq(count).addclass('active'); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -