last div in jQuery

Something Like that:
insertAfter

First we will see normal html code.
For that you need to create first html code.

HTML

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

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”dzjygg” default_tab=”html,result” user=”pradeepanvi”]See the Pen normal ul list by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

1
2
3
4
5

Now with a JS code that will be do 1 after 5.
For that you need to create first html code.

HTML

<ul>
  <li class="last">1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

Use jQuery Library.

After that add this JQuery code.

JS

$('.last').insertAfter('ul li:last-child');

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”rzrNQz” default_tab=”html,result” user=”pradeepanvi”]See the Pen last div in jquery by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

2
3
4
5
1

Leave a Reply

Your email address will not be published. Required fields are marked *