var sources; d3.json( "/json/podcast/podcast.json",function(d){ d3.select("#audioframe").attr("src",d[0].source); sources=d; }); d3.selectAll("p.ctitle").on('click', function(){ var this_id=d3.select(this).attr("value"); sources.forEach(function (d){ if(d.id == this_id){ d3.select("#audioframe").attr("src",d.source); window.scroll(0, d3.select("#sframe").node().getBoundingClientRect().top - d3.select("#stitle").node().getBoundingClientRect().top ); } }); });