Overview
JQuery replaceWith() Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>page</title>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<ul class="container">
<h2 class="title">Normal List</h2>
<li>Row 1</li>
<li>Row 2</li>
<li>Row 3</li>
<li>Row 4</li>
<li>Row 5</li>
<button class="btn btn-warning">CLICK</button>
</ul>
<script>
$(document).ready(function(){
$(".btn").click(function(){
$("h2").replaceWith("<h2>Bootstrap List</h2>")
$("li").replaceWith(function(){
return "<p class='list-group-item'>" + $(this).html() + "</p>";
});
$(this).remove();
})
})
</script>
</body>
</html>
Leave a comment