on-internet
← Community

jQuery play Audio

Stack Overflow ·

So i have been doing some JavaScript and is currently learning jQuery. Time to time i get a bit confused by how jQuery does things compared to JS. Got an HTML audio tag that looks something like this: <audio id="audio" src="audio.mp3"></audio> With JS i simply play it with: document.getElementById('audio').play(); So i figured, doing the same with jQuery would just be: $('#audio').play(); That doesn't work, instead i have to write it like this: $('#audio')[0].play(); Can anyone explain this to me? Thanks.

Comments

Sign in or sign up to comment and upvote.

No comments yet.