JSFiddle - React, Tailwind, and code Playground

HTML

<div>1</div>
<p>2</p>

<div>3</div>

JavaScript

$("div:first").replaceWith( $("div:first,p") );

$("div:last").replaceWith( 4, $("div:last") );