Question

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?

Was it helpful?

Solution

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

OTHER TIPS

$("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.

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

$("li.active a").text();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top