Page is a not externally linkable
Fotiman - 5:03 pm on Mar 12, 2013 (gmt 0)
do you know if it's possible to change the id trigger to a class
Yes, it's possible (though not as easy). Using an id is easy simply because the DOM provides the getElementById method, which is supported in all browsers. However, the getElementsByClassName is not supported by IE8 or below, so if you want to support those browsers, you can't rely on it, which means a more involved approach is needed to find the elements. You could write your own method for searching the DOM by classname (if you were using one of libraries like jQuery, that functionality is provided for you).
However, you could rework the above code to use multiple ID's but still not be "overkill":
var triggerElements = [
document.getElementById('trigger'),
document.getElementById('trigger2')
],
addThisLoaded = false,
i;
for (i = 0; i < triggerElements.length; i++) {
triggerElements[i].onmouseover = function () {
if (!addThisLoaded) {
loadScript("http://s7.addthis.com/js/250/addthis_widget.js#pub=example",
function() {
addThisLoaded = true;
});
}
};
}