File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Inexplicable behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Inexplicable behaviour" Watch "Inexplicable behaviour" New topic

Inexplicable behaviour

Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Yesterday I was attempting to write a script wherein, I had this Table with a single row and about 10 cells in it. This row was to serve as the header of a table and the user had the option of selecting which all cells he/she wanted in the table for the header row. For every cell, there was a checkbox the user could check/uncheck to add/remove the cell from the row. The checkbox's value was the same as the cell's ID.
Initially what I did was:

In IE this worked just fine, but in FF and Opera the behaviour was completely erratic. The cells got merged into other cells and messed up the display.
Then I created a CSS class named : "hideElems" which had a single property:
display: none;
And I changed the code above to:

Now it worked fine on all browsers. Can anyone explain this?
It's getting to be quite a nagging curiosity. And also, maybe there is something about not fiddling with inline style as opposed to switching between CSS classes from JavaScript?
[ April 01, 2008: Message edited by: Anirvan Majumdar ]
Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
i don't see any issues with the block of code, however can you also make sure that after that line are you doing some code which may reset the value.

I quite confident that the code is correct, however if you feel then you can easly debug the javascript in mozilla when compared to IE.

Try fireBug (mozilla addons), after knowing the firebug i started to love javascript programming..

let me if you have any updates...if you still unable to find the bug, please post the code here....

My Thoughts :
Try not to become a man of success but rather to become a man of value.
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Hello Mohammed,

I don't think there's anything wrong with the script. Firebug doesn't throw any errors either. As for the code, I think you can try it locally by just creating an HTML document and pasting the code below. At present, I'm taking the style.display approach. In IE it'll work fine, but in FF if you deselect a couple of checkboxes and then reselect them then you'll see what I mean.
After that, just uncomment the the commented script and comment out the style.display part of the script. You'll see that it works fine in FF too now. Let me know if you need something else to see what I mean.

Hopefully someone out there can tell me what causes these aberrant behaviour.

NOTE: You'll need to replace all occurrences of "onclic" with "onclick" to make this code work. The ranch doesn't allow posting of code containing certain script keywords :-/

[ April 01, 2008: Message edited by: Anirvan Majumdar ]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Firefox is probably expecting


you can just do

display=""; which sets it to the default value

Showing and hiding table cells is probably not the best thing to do.

I agree. Here's the link:
subject: Inexplicable behaviour
jQuery in Action, 3rd edition