Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Saturday, August 25, 2007

Show Hide using display.style in javascript problem in Firefox

An already javascript function was used to show/hide an array of elments in an HTML page.
It worked perfectly in IE but in Firefox it gave a problem when we used to show/hide multiple times on an element. A new row/column was added in every iteration of show hide.

On investigation, a single line code change made in work fine in both IE and firefox

Old Code
function showHideElement(elementId, showHideFlag) {
var elementObj = document.getElementById(elementId);
if(showHideFlag == 1) {
elementObj.style.display = 'block';
} else if(showHideFlag == 0) {
elementObj.style.display = 'none';
}
}
New Code
function showHideElement(elementId, showHideFlag) {
var elementObj = document.getElementById(elementId);
if(showHideFlag == 1) {
elementObj.style.display = '';
} else if(showHideFlag == 0) {
elementObj.style.display = 'none';
}
}
A single line change from elementObj.style.display = 'block' to elementObj.style.display = '' stopped creation of blank rows/columns on every iteration of show hide

http://www.ozzu.com/ftopic41924.html
http://www.velocityreviews.com/forums/t160487-firefox-and-stylequotdisplayblockquot-on-table-row.html