6

I have script that removes an h4 element then animates a hidden form in its place. I am trying to check if the h4 element has been removed so that if the same button is pressed ,while the form is visible, it will then animate out.

Here is the first part of my code

$('#editMapItem h4').remove();
manycheese
  • 3,605
  • 2
  • 18
  • 11

1 Answers1

7

check the length of the selector, like this:

$('#editMapItem h4').length

if it = 0, you've removed it already.

nathan gonzalez
  • 11,817
  • 4
  • 41
  • 57
  • 3
    This will though if you store `$('#editMapItem h4')` in a variable (which is generally a good idea for performance optimization). [How do I check whether a jQuery element is in the DOM?](http://stackoverflow.com/q/3086068/323407) has a more generic method. – Tgr Jun 27 '14 at 21:42
  • This is kind of checking element exists or not.I don't think this is the correct answer for this answer. I hoped it a callback to call when removing element is complete. – Zugor Apr 04 '18 at 06:52