ed1t
ed1t

Reputation: 8699

problems adding <li> into <ul> from javascript

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>');                    

Upvotes: 1

Views: 143

Answers (3)

Andrew Shepherd
Andrew Shepherd

Reputation: 45252

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"

Upvotes: 3

Nam Nguyen
Nam Nguyen

Reputation: 61

<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>');  

Upvotes: 0

JesseBuesking
JesseBuesking

Reputation: 6586

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")

Upvotes: 1

Related Questions