1

I have this following where I would like to dynamically add the list elements to it:

<ul name='eval-options' class="inputs-list">                                                                                    
</ul>

I'm adding the list elements with the following js but it is not working

 $("#eval-options ul").append('<li><label><input type="checkbox" name="optionsCheckboxes" value="option1" /><span>Option one</span></label></li>');                    
3
  • 4
    name='eval-options' needs to be id='eval-options'. # is an id selector. Commented Nov 29, 2011 at 2:23
  • 1
    Not working? Fix it, that always works! You want a more specific answer, ask a more specific question. Not working how? Commented Nov 29, 2011 at 2:24
  • Is there an ancestor of the ul that has the ID eval-options? That's what your selector is looking for. Commented Nov 29, 2011 at 2:28

3 Answers 3

3

First of all, declare the ul with an id of eval-options, instead of a name.

<ul id='eval-options' class="inputs-list">                                                                                     
</ul> 

Secondly, the string for your selector should be

$('#eval-options')

The selector you're currently using:

$('#eval-options ul')

means "the ul element contained as a child of any element with the identifier eval-options"

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

Comments

1

That would be because # reference's an id. What you want is to find the name (or the class) of your ul.

Change

$("#eval-option ul")

to

$("ul[name=eval-options]")

or

$(".inputs-list")

Comments

0
<ul id='eval-options' class="inputs-list">                                                                                    
</ul>


 $("#eval-options").append('<li><label><input type="checkbox" name="optionsCheckboxes" value="option1" /><span>Option one</span></label></li>');  

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.