var audio = new Audio('audio_file.mp3'); audio.play();

Same with displaying dynamic images (i'm using jquery here):

$(window).on('load', function() { $('#loadbutton').on('click', function() { var imagename = $('#imagename').val(); var imgpath = '/preview/' + imagename; // Input validation? Nah, there are no bad people on the internet ;-) $('#imagepreview').attr('src', imgpath); // Triggers loading of the new image source }); });