jquery - background color to an element which is positioned before the identified tag? -



jquery - background color to an element which is positioned before the identified tag? -

i'm trying add together background color element positioned before identified tag. example, know class of 1 elment , have list below.

<ul id="one"> <li><a href='#'>text0</a></li> <li><a href='#'>text1</a> <ul> <li><a href='#'>text2</a></li> <li><a href='#'>text3</a> <ul> <li class="item-1"><a href='#' class='identified'>item1</a></li> <li class="item-2"><a href='#'>item2</a></li> <li class="item-3"><a href='#'>item3</a></li> </ul> </li> <li class="item-c">c</li> </ul> </li> <li class="item-iii">iii</li> </ul>

now want assign background color 1st level element if know class='identified' want cange background color of text1 can create work.?

try using jquery closest method.

$('li.identified').closest('ul').closest('ul').prev().css('background', 'red');

.closest() reference: http://api.jquery.com/closest/

jquery html css-selectors background-color drop-down-menu

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -