views:

248

answers:

3

From the following HTML I need to figure out which List tag has class active and further on for the active List I need to find the relevant value

    <li class="active">
    <a href="value1" class="Tab1">Services</a>
    </li>
    <li><a href="value2" class="Tab2">Create Account</a>
    </li>
    <li><a href="value3" class="Tab3">Modify Account</a>
    </li>

What is the best way to do this?

+1  A: 

I think this is what you want, if you're wanting to see "Services":

$("li.active a").text();
gms8994
+3  A: 

$('li.active a').attr('href') would return 'value1'

Ken Browning
Thanks..what happens if my any chance 2 List tags have class active...which one takes preference?
Murtaza RC
According to the jQuery documentation, the `attr` function will "[a]ccess a property on the first matched element."
Ken Browning
+2  A: 
$("li.active a").text()

will retrieve the innerHTML

$("li.active a").attr("href")

will retrieve the path

and

$("li.active a").attr("class")

will retrieve the class.

EDIT: Updated the selectors to select the link and not the list item.

Sean Vieira
$("li.active").attr("href")this will not return me the <a> tags href value instead it will return the <li> href value.
Murtaza RC