Hello, there is a simple list:

<ul class="spisok"> <li><span>Текст</span></li> <li><span>Текст</span></li> <li><span>Текст</span></li> <li><span>Текст</span></li> </ul> 

How to add to the second element "li" red color to the text, given that you can add classes either to all or to none.

  • And what's the mark like this - [pure_js] ? - karmadro4
  • The label emphasizes that the decision is expected on a "clean" JS. - knes
  • 2
    Label for jQuery-фобов - Specter jQuery-фобов
  • And [javascript] then why? You just need to sprinkle excessively bred Rezig. Remember what Ockham said when he cut himself while shaving? - karmadro4

3 answers 3

It is possible so:

  li:nth-child(2) {color:red} 

    .eq ()

    Here, it is direct, EXACTLY, ONE in ONE your question. And the color is even red.

     $('li.spisok').eq(1).css('background-color', 'red');//вот с номером тока ошиблись. На единицу. 

     var classOfUl = 'spisok'; var WhichLi = 2; var uls = document.getElementsByTagName('ul'); for(var i=0;i<uls.count;i++){ if(uls[i].className==classOfUl){ var lis = uls.getElementsByTagName('li'); lis[(WhichLi-1)].style.color = 'red'; } } 
    • And without jQuery it is possible? I have mootools connected on another project, and accordingly all the plugins through it are dogmar
    • And why, I'm sorry, you indicated in the jquery tags? =) - knes
    • I confused, I haven’t tracked the label) - dogmar
    • For such cases, I created a special label. = ( - knes
    • one
      No need to apologize =) If it suits you best, take it! - knes

    ul li:first-child+li

    Like so.