Class Detection
We include our ‘core’ library, in the header
<script src="../Include/Core.js" type="text/javascript"></script>
The function ssHasClass() works out whether an element has a class or not.
It takes in an element and a class as parameters and returns true
or false
.
Here we use it as we loop through a set of elements, to check whether each one has the class ‘alert’.
function prepareAlerts()
{
var anchors = document.getElementsByTagName("a");
for (var aCount=0; aCount != anchors.length; aCount++)
{
if (ssHasClass(anchors[aCount],"alert"))
{
ssAddEvent(anchors[aCount], "click", showAlert, false);
}
}
}
An easier way to deal with a set of elements is provided by our other class detection function ssGetElementsByClass().