user1563944
user1563944

Reputation: 403

Get current active class of an ul

Say you have the following.

  .pic {
      display: none;
    }

    .pic.show {
      display: block;
    }

    <ul>
       <li class='pic show'><img src="1.jpg"></li>
       <li class='pic'><img src="2.jpg"></li>
       <li class='pic'><img src="3.jpg"></li>
       <li class='pic'><img src="4.jpg"></li>
    </ul>

I want to write a simple dynamic bit of jQuery that would find the li that has the class = 'pic show'.

So my question is, how would you go about finding the li that has the current class of class = 'pic show' applied to it?

Upvotes: 0

Views: 2499

Answers (2)

dotty
dotty

Reputation: 41433

Use $("ul li.show") to find the li element with a class of show which is a child of the ul.

Upvotes: 1

David Thomas
David Thomas

Reputation: 253318

Use the same selector as in your CSS:

$('.pic.show')

If you want to specify that it must be an li element:

$('li.pic.show')

Upvotes: 0

Related Questions