Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

document.querySelector - how to add and remove an element

Hi..

I can add an element using the following

              var rect = document.createElement('div');

              var el = document.querySelector('.results').appendChild(rect);


How can I then remove it ?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

el.parentNode.removeChild(el);
Avatar of JElster

ASKER

How do I check if it exists and then remove it.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JElster

ASKER

How can I check the document, before I add it so I don't add it again.
This code will be in a click event
thx