javascript - Swapping video tags is making the entire div empty -


i using janus stream video.

i have 2 div tags, 1 bigger other , i'm keeping option swap elements. these div tags contain video tags. have 2 video tags, 1 in local video being streamed , in remote video being streamed. following function i've attempted.

var swappingvideofunction = function() {      var localvideo = $("#videolocal").html();    var remotevideo = $("#videoremote1").html();    console.log(localvideo);    $("#videolocal").html(remotevideo);    $("#videoremote1").html(localvideo);    }

i can see in html on inspecting, video tag present in desired div video goes blank. complete div looks empty. case video tags in general? there approach it?

so thinking object writing updating reference. why jquery clone() function comes handy remove reference original object.

check out following code snippet.

var swappingvideofunction = function() {    var localvideo = $("#videolocal").clone();    var remotevideo = $("#videoremote1").clone();    $("#videolocal").html(remotevideo.html());    $("#videoremote1").html(localvideo.html());  }
.green {    height: 50%;    background-color: green;    padding: 10px;    box-sizing: contain;  }  .red {    height: 50%;    background-color: red;    padding: 10px;    box-sizing: contain;  }    .swap-button {    float: right  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <button class="swap-button" onclick="swappingvideofunction()">do swap</button>  <div id="videolocal">    <video class="red" width="320" height="240" controls>      <source src="local.mp4" type="video/mp4">      <source src="local.ogg" type="video/ogg">      browser not support video tag.    </video>  </div>  <div id="videoremote1">    <video class="green" width="320" height="240" controls>      <source src="remote.mp4" type="video/mp4">      <source src="remote.ogg" type="video/ogg">      browser not support video tag.    </video>  </div>


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -