How to take several elements and play on a single item?

Asked

Viewed 78 times

2

Hi, I was wondering how I could get these li's all and put only in the first <ul>.

<ul>
    <li>1 </li>
    <li>2 </li>
    <li>3</li>
    <li>4 </li>
</ul>

<ul>
    <li>5 </li>
    <li>6 </li>
    <li>7 </li>
    <li>8 </li>
</ul>

<ul>
    <li>9 </li>
    <li>10</li>
</ul>
  • You want to erase the others ul?

2 answers

4


  • 1

    Thank you @Sergio your answer fit more into what I needed so I’ll mark it as correct ok.

3

$('li').each(function(){
        $('.nova-ul').append($(this));
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
        <li>1 </li>
        <li>2 </li>
        <li>3</li>
        <li>4 </li>
    </ul>

    <ul>
        <li>5 </li>
        <li>6 </li>
        <li>7 </li>
        <li>8 </li>
    </ul>

    <ul>
        <li>9 </li>
        <li>10</li>
    </ul>

<ul class="nova-ul"></ul>

But, as @Sergio asked, well if you want to delete <ul> original will have to add $('ul').not('.nova-ul').remove(); after the cycle each

Browser other questions tagged

You are not signed in. Login or sign up in order to post.