views:

47

answers:

3

Hi,

I have a small portion of code which works well on FF but I can't seem to get it to work on Safari unless I put an alert instruction anywhere inside of the whiles.

Anyone knows what may be the problem ?

    var liste_ele = document.getElementsByClassName('accordion_content');
    i=0;
 while(i<liste_ele.length)
 {
  var j=0;
  var liste_sel = liste_ele[i].getElementsByTagName('select');
  while(j<liste_sel.length)
  {
   liste_sel[j].style.visibility = '';
   j++;
  }
  i++;
 }
+2  A: 

Why don't you try setting visibility to visible instead of ''.

liste_sel[j].style.visibility = 'visible';

And are they really hidden by setting visibility to hidden or are the hidden by display:none that might also make a difference.

jitter
A: 

If putting an alert in your while loop solves the problem, it's almost certainly a timing issue. Where in the DOM is this code being run? Are you sure it's being run AFTER the elements you're trying to find are created?

A simple test would be to put your code inside a timeout:

  window.setTimeout(function(){   
    // your code here 
  },100);

If that works, then your issue is related to order of operations; make sure your DOM is created before attempting to access it.

jvenema
A: 

@jitter : I already tried to set visibility to visible, but I didn't have a result so I just tried '', hoping it would help. And yes, my elements are hidden and not undisplayed, otherwise my script wouldn't run perfect on FF.

@jvenema : This looks like a good solution indeed :)

Even though I don't know why would my elements not be created since they are initialised as visibility:hidden by another script in my firmware before I pass on them with this script :/

Anyway thanks, you just solved my problem (well I had solved it the good way, by modifying the script that sets it to hidden but I was curious :p) ! :)

R4PaSs
Please mark as accepted whichever solution solved the problem.
jvenema