0

I want to take "div" s and and this html in "li" .

This is my HTML code:

<ul class="NewContent">

    </ul>   
        <div class="test">
            <span>Text1</span>
        </div>

        <div class="test">
            <span>Text2</span>
        </div>

and jquery (not sure if it is ok started):

<script type="text/javascript">
        $(document).ready(function(){
            $('ul.NewContent').append("<li>"+ $('.test').html()+"</li>");
        });
    </script>

But the problem is, that I want to add each "div" content in new "li"

something like this:

output:

<ul class="NewContent">
            <li><span>Text1</span></li>
            <li><span>Text2</span></li>
        </ul> 

now is not good .. I need to add on array or something like this

Thanks !!

Sorry for My confusing description !

2 Answers 2

4

This should do it:

$(function() {
    $('.test').each(function() {
        $('ul.NewContent').append('<li>'+$(this).html()+'</li>');
        $(this).remove();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$(function() {
  $('ul.NewContent').html($.map($('div.test'), function(i, div) {
    return '<li>' + $(div).html() + '</li>';
  }).get().join(''));
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.