0

I have a HTML see below

here i trying to get all Li whose has class selectedLi,

I am trying

$("#coverage_ul li .selectedLi");

but this was not returning any thing

2
  • use $("coverage_ul li.selectedLi") ....that should resolve your issue Commented Nov 26, 2013 at 10:04
  • ...or just $("#coverage_ul .selectedLi"); will work as well. Commented Nov 26, 2013 at 10:04

3 Answers 3

3

Remove the space between li and .selectedLi:

$('#coverage li.selectedLi')

As it stands it's looking for a descendent of the li with that class, not an li with that class.

(FWIW, using selectedLi as the class name is probably a little over-the-top - it would be quite normal to just use selected and rely on the fact that the element is a <li> per the selector to choose the appropriate styles).

Sign up to request clarification or add additional context in comments.

Comments

3

try this

$("#coverage_ul li.selectedLi") 
//^^^^^^^^^^^remove space here between li and .selectedLi

if you use any selector with class then

first write element type then its (class or id) in your case like below

elementtype       class or id       =last result
li                .selectedLi       =li.selectedLi   

3 Comments

The bottom section of your answer is very confusing, IMHO.
perhaps, but the wording and layout make that far from obvious.
sorry @Alnitak can you suggest me how it write i want to explain that how OP make its selector
1

Try this:

$("#coverage_ul li.selectedLi")

Live Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.