JavaScript jquery click append and remove append second click jquery click append,jquery click append element,jquery click append

I am trying to make a append menu on click div. But i have one question here. How can i remove appended elements after second click. Anyone can help me in this regard ?

This is the DEMO page from codepen.io

Js

$(document).ready(function(){
   $("body").on("click", ".menu-button", function(event){
      event.preventDefault();
      $(".menu-container").append('<div class="button"></div><div class="rebackbar"></div><div class="abc" id="myDiv"></div><div class="lBrgF"><div class="card"><span class="three-quarters-loader">Loading&#8230; </span></div></div>');
   });

});
Answer:1

Seems like toggling the element instead of adding it would be better, but you could just put a check

var childNodes = $(".menu-container").children();
if (childNodes.length) {
    childNodes.remove();
} else {
    $(".menu-container").append("...");
}
Answer:2

Here's another solution I've called the dblclick event to empty the contents of the menu-container.This empties the entire div.Incase you want to remove the last child, you can find the length and remove the last one that way.

$("body").on("dblclick", ".menu-button", function(event){
         $(".menu-container").empty();
     });

Working Demo

Answer:3

By no means the most elegant solution but probably the easiest:

$(document).ready(function(){
   $("body").on("click", ".menu-button", function(event){
      event.preventDefault();
      if($('.menu-container').html().length > 0) {
         $(".menu-container").html(null)
      }
      else {
         $(".menu-container").html('<div class="button"></div><div class="rebackbar"></div><div class="abc" id="myDiv"></div><div class="lBrgF"><div class="card"><span class="three-quarters-loader">Loading&#8230; </span></div></div>');
      }
   });

});
Answer:4

I understand that when index names are used to push values in Javascript, they essentially work like objects. But what I don't understand is the following behaviour - person = []; person[0] = "...

I understand that when index names are used to push values in Javascript, they essentially work like objects. But what I don't understand is the following behaviour - person = []; person[0] = "...

I am new with javascript. I want to display a message in the client side if a person press a button continuously. So I think it is better to use a javascript code to show an Alert message if someone ...

I am new with javascript. I want to display a message in the client side if a person press a button continuously. So I think it is better to use a javascript code to show an Alert message if someone ...

  1. alert next line
  2. alert next line javascript

Im new to angular and while doing a small exercise, i was struck and I wanted to enable the ng-show depending upon previous row timings and time input is through jquery timepicker, but my angular is ...

Im new to angular and while doing a small exercise, i was struck and I wanted to enable the ng-show depending upon previous row timings and time input is through jquery timepicker, but my angular is ...

  1. angular-jquery-timepicker
  2. angular-jquery-timepicker npm
  3. angularjs jquery timepicker
  4. angular jquery datepicker
  5. angular jquery datepicker example
  6. angular jquery datetimepicker
  7. angularjs jquery datepicker
  8. angularjs jquery datepicker not binding
  9. angularjs jquery datepicker not working
  10. angularjs jquery datetimepicker
  11. angularjs jquery datepicker directive
  12. jquery timepicker angular 2

am trying to do a ConditionExpression in a DynamoDB put to check whether a stored boolean is true (in this example, whether the user is already verified don't run the put), i'm using the javascript ...

am trying to do a ConditionExpression in a DynamoDB put to check whether a stored boolean is true (in this example, whether the user is already verified don't run the put), i'm using the javascript ...

  1. dynamodb putitem conditionexpression example
  2. dynamodb putitem conditionexpression
  3. dynamodb putitem conditionexpression python
  4. dynamodb putitem conditionexpression java
  5. boto3 dynamodb put_item conditionexpression
  6. dynamodb put_item conditionexpression