Reputation: 8699
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
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
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
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