Selecting a specific element by class amongst many others...
I have a list, in which each <li> there is an element, which I´d like to toggle an event when clicked on it.
- <ul>
- <li class="someclass">
- <a href="#" class="foo">click here</a>
- <div class="bar">
- show this on click
- </div>
- </li>
- <li class="someclass">
- <a href="#" class="foo">click here</a>
- <div class="bar">
- show this on click
- </div>
- </li>
- </ul>
Using jquery I should be able to do something like this:
- $(document).ready(function() {
- $(".foo").click(function(){
- $(".bar").slideDown("fast");
- return false;
- });
-
- });
But as you may expect, both div.bar are affected by my puny jquery-code. I don´t want to apply id´s to the divs, as there might be about 200 of them. Is it possible to select the div.bar, related to the parent <li>?
Something like (forgive my noobish code... just to clarify... I´m completely new to this and a pea-brain...)
- $(document).ready(function() {
- $(".foo").click(function(){
- $this.parent.li.(".bar").slideDown("fast");
- return false;
- });
-
- });
Thanks blackmane