Hi Guys,
I have scenario when I have ul and inside the ul I insert dynamic li with jquery.

Please look at the code:
var rows = $("#addnew_product").append("<li style='font-size:16px'>" + txt + "</li>");

Open in new window

I limited users to insert 4 li in total and after the finish to insert the li I want to grab the text for each li the insert and for this I did something like that.

                var row1 ="li:nth-child(0)");
                var row2 ="li:nth-child(1)");
                var row3 ="li:nth-child(2)");
                var row4 ="li:nth-child(3)");

Open in new window

The issue with the code above is that each child show the same text and add the last text from the previous row.
My question:
How can I get the text from each dynamic li.?

thanks ,
Moti Mashiah.NET DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:

Try this sample to get the values.

<script type="text/javascript">
    $("#Button1").click(function () {

        var items = [];
        for (var i = 0; i < 3; i++) {

           items.push("<li style='font-size:16px' data-id='Hello" + i + "'>Hello" + i + "</li>");



        //To Read the values
        $("#addnew_product li").each(function () {



Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moti Mashiah.NET DeveloperAuthor Commented:
Thank you for your answer, but I found the way of doing it:

var ul1 = $("#addnew_product li:nth-child(1)");
var ul2 = $("#addnew_product li:nth-child(2)");
var ul3 = $("#addnew_product li:nth-child(3)");

after user finish to insert row dynamically I just take all the child from another method.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.