Selecting an element by the data- attribute
In order to determine if there is a way around the performance hit of selecting by a data- attribute I created the following jsperf: http://jsperf.com/generictestjsperf
by Matt Rummler
HTML
<body id="testbody" data-infopanel="">
If we see this then the selector likely failed
</body>
JavaScript
var element='initial value';
element=document.querySelector('[data-infopanel]');
element.innerHTML='The selector selected the element!';
/*
To make this technique perform well do not do document.querySelector instead select an element by ID then do element.querySelector. When data- is selected this way the performance is actually impressive.
See: http://jsperf.com/generictestjsperf
*/