Reputation: 1752
I'm completely STUCK with this very simple task, I would be glad for any advice.
I've created a dropdown menu for user selection using <ul>
and <li>
. Once the user clicks on a certain menu Item (from the class submen
), this item gets the class active
assigned to it.
<ul id="firstid">
<li id="secondid"><a href="#">Title1</a>
<ul class = "submen">
<li class = "active"><a href="#">Option1</a></li>
<li><a href="#">Option2</a></li>
</ul>
</li>
</ul>
Now I want to retrieve the text "Option1" since the user has selected this item in the above example and its class is active
. How do I go about this using jQuery? This doesn't seem to work:
var selected_option = $("#secondid" ".submen" ".active" "a").text();
Upvotes: 0
Views: 77
Reputation: 458
Chained selector looks like this:
var selected_option = $("#secondid .submen .active a").text();
Upvotes: 1