javascript - Store html into variable on click, erase from the DOM and put it back in on another click -
i'm trying build on/off button video. i'd simple: on first click, deletes video (not stop it) and, on second, puts dom.
i've come bit of code, doesn't work way want to:
$('#on-off').click(function(e) { e.preventdefault(); if (videocontent !== ""){ var videocontent = $('#video-container').html(); console.log(videocontent); // @ point, console shows variable videocontent contain content of #video-container. $('#video-container').html(""); } else { $('#video-container').html(videocontent); } });
the first click works fine , stores content of #video-container videocontent. second doesn't put content of videocontent in #video-container, however. in fact, erases content of videocontent.
i'm sure pretty simple solve, can't figure out. thanks
put variable videocontent
in global scope:
var videocontent = ''; $('#on-off').click(function(e) { e.preventdefault(); if (videocontent !== ""){ videocontent = $('#video-container').html(); $('#video-container').html(""); } else { $('#video-container').html(videocontent); } });
Comments
Post a Comment