JQuery checking if a video has height / width

I have an element <video>generated by js and I need to get its height and width.

var v = $('video'); v.height() returns null, because when it starts, the video is not yet loaded, so there are no dimensions in the DOM.

How to check if the video received a measurement, and if not, wait until it receives the height and width.

Thank.

Edit:

I created jsbin with my sample code:

http://jsbin.com/udazu/2/edit

Thank.

Edit: screams, made a mistake in the sample code.

+3
source share
1 answer

Update based on new code . You can use loadedmetadataevent for this , I updated your jsbin example here

$('input').click(function () {
  $('#thumbnail video').clone().bind('loadedmetadata', function() {
    alert($('#viewing-area video').height());
  }).appendTo('#viewing-area');
});
+5

Source: https://habr.com/ru/post/1742904/


All Articles