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.
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('#div-wordpress').slideToggle('230','swing','hide');
jQuery(this).remove();//supposed to be #my-button ?
});
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
/* Show/Hide my div*/
jQuery(document).on('click','.my-button',function() {
//jQuery('.div-wordpress').slideToggle('230','swing','hide');
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
