CurrentSrc does not work inside jquery plugin

"currentSrc" is the only option, I have to switch the source src to html5 video with multiple sources (* .mp3, * .ogg, etc.)

"currentSrc" throws out "undefined" if I use jQuery inside. But it works fine if I call this on the html page.

Read more: My video source:

<video width="630" height="354" id="video1" class="video1" poster="asserts/poster.png" controls="controls" data-name="demo video" data-uid="57fb2708"> <source src="http://static.clipcanvas.com/sample/clipcanvas_14348_H264_320x180.mp4" data-quality="sd" /> <source src="asserts/samllfile.mp4" data-quality="hd" /> <source src="http://static.clipcanvas.com/elephants-dream.webm" data-quality="hd" /> <source src="http://video.webmfiles.org/big-buck-bunny_trailer.webm" data-quality="sd"/> <source src="http://video.webmfiles.org/elephants-dream.webm" data-quality="hd" /> </video> 

Get current video url

Javascript on html page (works fine):

 myVid=document.getElementById("video1"); function getVid(){ alert(myVid.currentSrc); }; 

String inside jQuery (throws "undefined"):

 alert($hdVideo.currentSrc); 

Please help me...

+4
source share
2 answers

Since the jQuery object does not have the currentSrc property, it returns undefined.

 alert( $hdVideo.get(0).currentSrc ); alert( $hdVideo[0].currentSrc ); alert( $hdVideo.prop("currentSrc") ); //might be attr() instead of prop() 
+5
source

DOM elements and DOM elements wrapped in jQuery do not have the same properties or methods. If you want to access the property of a DOM element from a DOM element wrapped in jQuery, you need to use get() or an index to access the underlying DOM element:

 alert($hdVideo.get(0).currentSrc); alert($hdVideo[0].currentSrc); 
+3
source

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


All Articles