Add button under the div using the after () function

0

Good afternoon!

I have the following situation:

Multiple divs, side by side, using display: inline-block.

I want to click on a div, I can put a button underneath of this div.

I started using the append function of jQuery, as follows:

   $(".classeDaDiv").click(function() { 
      $(this).append("<button>Titulo</button>");
   })

No problem so far, did what I wanted. The problem is that I need to remove this button when I click on the div again. So I implemented that too. I am     

asked by anonymous 25.08.2016 / 21:20

1 answer

0

To insert an element after it has been clicked, you should use the insertAfter function of jQuery.

Change your code to the following:

$(".classeDaDiv").click(function() {
   $('<button>Titulo</button>').insertAfter(this);
});
    
14.11.2016 / 21:24