[jQuery] Selecting based on attr Class
I cant seem to figure out how to get this to work.. but If i have the
list below.. I want whatever <a> i click on i want the parent <li> to
have the class=".selected" appended to it, and whatever <li> currently
has that attr to have it removed, I can obviously get the append part
to work, but I am having trouble getting the remove part to work..
<dt class="widget-middle">
<ul>
<li class=".selected"><a href="#" name="modules/test.html">Add a
Main Widget </a></li>
<li><a href="#" name="modules/test.html">Search for a Main Widget </
a></li>
<li><a href="#" name="modules/test.html">List the Main Widgets </
a></li>
</ul>
</dt>
I have tried a couple things and none of them give me what i want:
alert($(this).parent().html()); // Outputs everything inside the <li>
that was clicked
alert($(this).parent().siblings(".selected").html()); // null
alert($(this).parent().parent().html()); // Outputs everything inside
the <ul> that was clicked
alert($(this).parent().parent().children(".selected").html()); // null
alert($(this).parent().parent().html()); // Outputs everything inside
the <ul> that was clicked
alert($(this).parent().parent().filter(".selected").html()); // null
There may be some more that I tried, I just forgot..
This is my function:
$("dl").find("dt.widget-
middle").find("ul").find("li").find("a").click(function(){
});
Thanks in advanced!
James