williamrouse Posted February 23, 2009 Report Posted February 23, 2009 List 1 List 2 List 3 List 4 Add List Item Remove List Item List 1 List 2 List 3 List 4 Quote
monkeysaurus Posted February 28, 2009 Report Posted February 28, 2009 List 1 List 2 List 3 List 4 Add List Item Remove List Item List 1 List 2 List 3 List 4 Quote
williamrouse Posted February 28, 2009 Author Report Posted February 28, 2009 (edited) Yep! That's it. Thanks! Edited February 28, 2009 by williamrouse Quote
k1d Posted October 15, 2009 Report Posted October 15, 2009 what should I do if I have two ordered list or more?? I try it but it doesn't work. Can somebody help me? Quote
falkencreative Posted October 15, 2009 Report Posted October 15, 2009 You'd probably need to duplicate the jquery as shown below, but use different variable names and id names for #remove and #add, and your list: > $(function(){ var i=$('ul#loc li').size() + 1; $('a#add').click(function(){ $('</pre> <li> List ' + i + '</li>').appendTo('ul#loc');<br> i++;<br> });<br><br> $('a#remove').click(function(){ <br> $('ul#loc li:last').remove();<br> i--;<br> });<br> }) Quote
k1d Posted October 16, 2009 Report Posted October 16, 2009 Can I find another way to not duplicate it?? if I have ten ordered list so I have to make ten another script. It's very confusing... Quote
k1d Posted October 16, 2009 Report Posted October 16, 2009 ohh.. I forget to ask this. Why jquery just work for one id?? Quote
falkencreative Posted October 16, 2009 Report Posted October 16, 2009 I found a partial solution... Perhaps Monkeysaurus will be able to tweak it to get it working. Basically, this same assumes that your add/remove links are in the last in the unordered list. The jquery then looks for the previous and removes it (if remove is clicked) or adds one (if add is clicked.) Unfortunately, the current jquery adds the within the previous li (not outside the closing tag)... not exactly what I wanted. Still, in case it helps: > title <br /> $(function(){<br /><br /> $('a.add').click(function(){<br /> $(this).closest("li").prev("li").append("<li>test");<br /> });<br /><br /> $('a.remove').click(function(event){ <br /> $(this).closest("li").prev("li").remove();<br /> });<br /><br /> });<br /><br /> </pre> <ul id="loc"> List 1 List 2 List 3 List 4 Remove List Item | Add List Item </ul> <br><br><ul> List 1 List 2 List 3 List 4 </ul> <br><br Quote
BeeDev Posted October 19, 2009 Report Posted October 19, 2009 (edited) Or you can use .each(): $("a.add").each(function(counter){ $(this).click(function(){ $("ul:eq("+counter+") li").append("New one"); }); }); Edited October 21, 2009 by BeeDev Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.