I have this JavaScript function that is the click event handler for some
anchor tags.
function switchNotes(e) {
var targ = setTarget(e);
var divId = targ.href.split("#")[1];
var div = document.getElementById("notes");
for (i = 1; i < div.childNodes.length; i++) {
if (div.childNodes[i].id == divId + "Notes") {
div.childNodes[i].style.display = "block";
}
else if (div.childNodes[i].id && div.childNodes[i].id != 'tabs'){
div.childNodes[i].style.display = "none";
}
}
div = document.getElementById("tabs");
for (i = 0; i < div.childNodes.length; i++) {
if (div.childNodes[i] == targ) {
div.childNodes[i].style.backgroundColor = "#fff";
}
else if(div.childNodes[i].nodeName == "A") {
div.childNodes[i].style.backgroundColor = "#999";
}
}
return false;
}
As you can see, at the end of the function I am returning false as I
don't want to default anchor click event handler to fire. But, I
presume, since I am using the following JavaScript function to attach my
event handler that I am not setting it up so that the default handler
can be stopped.
function addEventSimple(obj,evt,fn) {
if (obj.addEventListener)
obj.addEventListener(evt,fn,false);
else if (obj.attachEvent)
obj.attachEvent('on'+evt,fn);
}
This function is called like so to attach the desire events to the
desired controls.
addEventSimple(div.childNodes[i],"click",switchNotes);
Is there something I need to do to provide the equivalent to if I had
done this inline?
<a href="#player" onclick="return switchNotes()">Player Notes</a>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-community/message.cfm/messageid:316193
Subscription: http://www.houseoffusion.com/groups/cf-community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-community/unsubscribe.cfm