View Full Version : Set current time of html5 audio with link

03-22-2013, 12:50 AM
Does anyone know how to set the currentTime property of html5 audio by clicking a link with a time? Similar to how Youtube does it? Say I click a link "3:10", it will instantly change the currently playing audio's currentTime to 3:10.

<audio controls loop class="sound">
<source src="../../site/music/music1.mp3"/>
<source src="../../site/music/music2.ogg"/>

Lorem ipsum dolor sit amet, <b><a>3:10</a></b> consectetur adipiscing elit <b><a>4:10</a></b>.

I'm mainly just having difficulty obtaining the time from the link. I only want to have one function covering all time links, obviously I don't want to have this:

$('.3_10').on('click', function(e){
//set time to 3:10
$('.3_15').on('click', function(e){
//set time to 3:15
$('.3_17').on('click', function(e){
//set time to 3:17
$('.4_10').on('click', function(e){
//set time to 4:10

Instead I need to fetch the time from the link like this:

$('.timelink').on('click', function(e){
//get the time from the link
//set currentTime to target time