 <p>You could check if the <code>#localVideo</code> element exists. Also, if they are the only elements in the <code>#A</code> element, you can remove them by calling <code>$('#A').empty();</code>.</p> <pre><code>$(document).ready(function() { $('#BtnOn').click(function() { if ($('#localVideo').length == 0) { $('#A').append('&lt;video id="localVideo" style="background-color:black"&gt;&lt;/video&gt;&lt;div id="remoteVideos"&gt;&lt;/div&gt;'); } }); $('#BtnOff').click(function() { if ($('#localVideo').length &gt; 0) { $("#localVideo").remove(); $("#remoteVideos").remove(); } }); }); </code></pre> <p>You could also consider hiding and showing the video elements, rather than adding and removing them.</p>