Playing with jQuery,

I wanted to remove the button after displaying div (#div-wordpress)

I thought I understood the trick but no ... It didn't work I think I forgot something.

enter image description here

if someone can show me the most modern and easy way to do it

clic = Show div and Remove the button

My code

/* Show/Hide my div*/   
jQuery(document).on('click','#my-button',function() {
      jQuery(this).remove();//supposed to be #my-button ?
  • This isn't a WordPress query, you should ask this on stackoverflow instead – Tom J Nowell Jan 11 at 22:31
/* Show/Hide my div*/   
jQuery(document).on('click','.my-button',function() {
  this.remove();//supposed to be #my-button ?

Note that I have swapped ids for classes and just made a small JS update - this is the clicked element inside a jQuery event - not jQuery(this)

Here is a CodePen: https://codepen.io/qstudio/pen/PoGdLgX

  • I think you misunderstood, I want to keep .div-wordpress and only delete .my-button – neosan Jan 11 at 22:12
  • jQuery('.div-wordpress').slideToggle('230','swing','hide'); - your original code "toggled" the div - this would hide it, if it was shown.. – Q Studio Jan 11 at 22:13
  • Updated to only hide the click button element – Q Studio Jan 11 at 22:14
  • Thank you Q Studio I learned how to do it – neosan Jan 11 at 22:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.