Populating a list dynamically (jQuery)?

Quick and concise version. $('a'). Click(function() { $('ul').children().clone().

AppendTo('ul'); }) Of course, you may want to define your 'a' and 'ul' with a class or id in order to be more specific. EDIT: To expand on the disclaimer given above, this will be a somewhat fragile solution as it will affect all 'a' and 'ul' elements. This may likely not be what you desire.

Better form is to give your html elements classes or ids, and then attach events to those. Example: $('#myPopulateAnchorElement'). Click(function() { $('#myExpandableUL').children().clone().

AppendTo('#myExpandableUL'); }); item x item y item z Populate With thanks to Ed Woodcock for suggesting the inclusion of a preemptive solution.

This will break quite badly if there's another UL on the page though. It's almost always a bad idea to use jQuery without class or id selectors! – Ed Woodcock Feb 4 '10 at 15:58 @Ed Woodcock - Read the rest of my answer... I was working with what I was given, then suggested specifying the 'a' and 'ul' with a class or id.

– user113716 Feb 4 '10 at 16:11 Yes, I didn't disagree with your answer, I was just stating that it was bad to not use selectors: the problem with posting semi-correct code like your answer is that the inexperienced or confused will use the code without reading the rest of the answer, and that's a bad thing! – Ed Woodcock Feb 4 '10 at 16:27 1 @Ed Woodcock - Point taken, though I prefer to give an answer that is specific to the question accompanied by a warning if warranted. Perhaps it would be better if I were to add an alternate answer in case the context of the page didn't allow for the specific answer to function properly.

I'll update my answer with such. – user113716 Feb 4 '10 at 16:41 fair enough, it's just that you often find people on here latch onto a bad solution even when told of the pitfalls so it can be good to point out better ways of doing things straight off! :) – Ed Woodcock Feb 4 '10 at 17:10.

Var ul = $('ul'); $('a'). Click(function(){ ul.children(). Clone(true).

AppendTo(ul); }).

Try this: $(function(){ $('. AnchorClass'). Click(function(){ var ul = $('.

UlClass'); ul. Append(ul.html()); }); }); EDIT: You'll need to change your html to: item x item y item z Populate.

You can do something like this: $('a'). Click(function(){ $('li'). Each(function(){ $(this).clone().

AppendTo('your selector where to put the copy'); }) }).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions