0

hi,
i'm trying to add a background color to a element which is positioned before the identified tag. for example, i know the class of one elment and i have a list like 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 i want to assign a background color to the 1st level element if i know class='identified' i want to cange the background color of <a href='#'>text1</a> i used this code which is obviously wrong, since there is repeating <a> tags.
what can i do to make this work.?

$('ul li a.identified').closest('a')
 		.css('background-color', 'red');
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Virangya
0

Try this one:

$('ul#one > li:has(a.identified) > a').css('background-color', 'red');

thanks...
how ever i did it by using parent() several times.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.