Reputation: 282
Following is my fiddle in which I am dynamically adding LIs. The issue I am facing is that the Parent UL
in which I am trying to add Lis
already consist child UL
within the Parent LI
and on generating dynamically a new Li. The Li not only created for parent UL but also for child UL. Kindly let me know how can I change following fiddle so the (Dynamically Created) LI will only be created for Parent <ul>
$("#butadd").click(function () {
$("ul").append("<li>Folder Name : <input type='text' class='fname' value='' required='required' /> <input type='button' class='liDelete' value='- Remove' /> <ul class='anotherUL'><li>Dynamic Child Li</li></ul> </li>");
});
Upvotes: 0
Views: 78
Reputation: 97672
$("ul").append
is targetting all the ul
s you have to specifically select the ul you want, which is #folder
$("#folder").append("<li>Folder Name : <input type='text' class='fname' value='' required='required' /> <input type='button' class='liDelete' value='- Remove' /> <ul class='anotherUL'><li>Dynamic Child Li</li></ul> </li>");
Upvotes: 2
Reputation: 133403
As you have already provide an id to UL, use and change your selector as
$("ul#folder").append("<li>Folder Name : <input type='text' class='fname' value='' required='required' /> <input type='button' class='liDelete' value='- Remove' /> <ul class='anotherUL'><li>Dynamic Child Li</li></ul> </li>");
$("ul").append()
will target to all uls
Upvotes: 1