I'm using a great visualization library called d3 and I'm finding myself with code that looks very much like the following all over the place:
<span id="sparkline"></span>
<script type="text/javascript">
drawSparkline('#target', [10, 20, 30, 40]);
// or
drawSparkline('#target', 'http://data.com/location'));
</script>
Is there a way to make this more expressive by embedding the code that acts on the dom element directly as an attribute? Perhaps something like this:
<span onload="drawSparkline(this, [10, 20, 30, 40])"></span>
<span onload="drawSparkline(this, 'http://data.com/location')"></span>
Perhaps something like:
<span data-onload="drawSparkline(this, [10, 20, 30, 40])"></span>
With something at the beginning in jQuery like:
$(document).ready(function() {
$('*[data-onload]').each( eval the onload? );
});
What would be the appropriate way?