javascript - How to use jquery to get to previous li -
i have following html:
<li> <a href="#tab1" data-toggle="tab">presentation name</a> </li> <li> <a href="#tab2" data-toggle="tab" class="not-allowed" id="survey_kind">survey length</a> </li>
and here jquery:
var yolo = $('.not-allowed').first(); yolo.removeclass("not-allowed"); yolo.prev("li").addclass("active");
the first 2 lines of javascript working. reason, can't last line work. i'm trying have second li tag have class active, class not being added anywhere.
have @ example. think answers question: https://api.jquery.com/prev/
markup
<ul> <li>list item 1</li> <li>list item 2</li> <li class="third-item">list item 3</li> <li>list item 4</li> <li>list item 5</li> </ul>
jquery
$( "li.third-item" ).prev().css( "background-color", "red" );
i made jsfiddle here: https://jsfiddle.net/toreanjoel/nq6efza9/
Comments
Post a Comment