I ran across something today that took me a few minutes to figure out, so I thought I'd share it.
I was trying to make a column heading toggle the display of the column below when clicked. So I wrote up a quick function like this:
function toggleDivDisplay(divId) {
// call with toggleDivDisplay('#{javascript:getClientId("**XspIdHere**")}');
var div = document.getElementById(divId);
if (div.style.display == "") {
div.style.display = "none";
} else {
div.style.display = "";
}
}
This function was called from the onclick event for the heading Div I had created, and everything worked swimmingly. However when I used the same technique on a different column, it failed. I spent a few minutes making sure the target ID matched what I was sending, and sure enough it did, and I was left scratching my head.
That was when I realized how client-side JS is actually attached: it isn't added to the HTML element itself. A listener is created. And how can a listener listen to something with no ID? I checked, and sure enough the heading Div had been created with no ID at all. So I quickly added id="div1" and voilĂ - everything worked.
I was trying to make a column heading toggle the display of the column below when clicked. So I wrote up a quick function like this:
function toggleDivDisplay(divId) {
// call with toggleDivDisplay('#{javascript:getClientId("**XspIdHere**")}');
var div = document.getElementById(divId);
if (div.style.display == "") {
div.style.display = "none";
} else {
div.style.display = "";
}
}
This function was called from the onclick event for the heading Div I had created, and everything worked swimmingly. However when I used the same technique on a different column, it failed. I spent a few minutes making sure the target ID matched what I was sending, and sure enough it did, and I was left scratching my head.
That was when I realized how client-side JS is actually attached: it isn't added to the HTML element itself. A listener is created. And how can a listener listen to something with no ID? I checked, and sure enough the heading Div had been created with no ID at all. So I quickly added id="div1" and voilĂ - everything worked.
Comments
Post a Comment