Q:

jquery remove element


  
    $("button").click(function(){

   $("div").empty();

 });
  
 
5
$( ".hello" ).remove();
18
$("elementsSelector").replaceWith( "<h2>New content</h2>" );
2
Removing an element is much easier, as it only requires the element's ID.
1. function removeElement(elementId) {
2. // Removes an element from the document.
3. var element = document. getElementById(elementId);
4. element. parentNode. removeChild(element);
5. }

Example:
<h1>The remove() Method</h1>

<p>The remove() method removes the element from the DOM.</p>

<p id="demo">Click the button, and this paragraph will be removed from the DOM.</p>

<button onclick="myFunction()">Remove paragraph</button>

<script>
function myFunction() {
  var myobj = document.getElementById("demo");
  myobj.remove();
}
</script>
9
$( ".class" ).remove();
$( "#id" ).remove();
$( "div" ).remove();
0
.remove("#elemnt_id .elemnt_class");
4
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>empty demo</title>
  <style>
  p {
    background: yellow;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
 
<p>
  Hello, <span>Person</span> <em>and person</em>.
</p>
 
<button>Call empty() on above paragraph</button>
 
<script>
$( "button" ).click(function() {
  $( "p" ).empty();
});
</script>
 
</body>
</html>
0
$('#record_nav ul li').on('click', function(e){
      $('#record_nav ul li.selected').removeClass('selected');
      $(this).addClass('selected');
      $('.content').hide();
      var id = $(this).data('target');
      $(id).show();
  });
-1

New to Communities?

Join the community