jQuery - toggle the class of a parent element?

Posted by Nike on Stack Overflow See other posts from Stack Overflow or by Nike
Published on 2010-04-18T13:38:17Z Indexed on 2010/04/18 13:43 UTC
Read the original article Hit count: 540

Filed under:
|
|
|

Hello, again.

I have a few list elements, like this:

<li class="item">
    <a class="toggle"><h4>ämne<small>2010-04-17 kl 12:54 by <u>nike1</u></small></h4></a>
    <div class="meddel">
        <span>
            <img style="max-width: 70%; min-height: 70%;" src="profile-images/nike1.jpg" alt="" />
            <a href="account.php?usr=47">nike1</a>
        </span>

        <p>text</p>
        <span style="clear: both; display: block;"></span>
    </div>
</li>

<li class="item odd">
    <a class="toggle"><h4>test<small>2010-04-17 kl 15:01 by <u>nike1</u></small></h4></a>
    <div class="meddel">
        <span>
            <img style="max-width: 70%; min-height: 70%;" src="profile-images/nike1.jpg" alt="" />
            <a href="account.php?usr=47">nike1</a>
        </span>

        <p>test meddelande :) [a]http://youtube.com[/a]</p>
        <span style="clear: both; display: block;"></span>
    </div>
</li>

And i'm trying to figure out how to make it so that when you click a link with the class .toggle, the parent element (the li element) will toggle the class .current.

I'm not sure if the following code is correct or not, but it's not working.

$(this).parent('.item').toggleClass('.current', addOrRemove);

Even if i remove "('.item')", it doesn't seem to make any difference.

So, any ideas?

Thanks in advance, -Nike

© Stack Overflow or respective owner

Related posts about toggle

Related posts about class