954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

background color to a element which is positioned before the identified tag

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 tags.
what can i do to make this work.?

$('ul li a.identified').closest('a')
.css('background-color', 'red');

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Try this one:

$('ul#one > li:has(a.identified) > a').css('background-color', 'red');
AleMonteiro
Junior Poster
164 posts since Aug 2010
Reputation Points: 15
Solved Threads: 30
 

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.

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: