I am using IE7 and Firefox. What I will describe below works perfectly in Firefox: this description is limited to the problem in IE7. I have used cloneNode(true) to clone a textbox, then changed its id attribute, and inserted it into the DOM with tbody.insertBefore. View Generated Source in Firefox and the IE Developers Toolbar both show that the generated source is perfect. When I do the following in IE, widgetArray.size does not reflect the dynamically added widget: var widgetArray = $$("#" + empTableId + " tbody .period td div input"); alert("widgetArray.size: " + widgetArray.size() ); // returns 28 Specifically, there were 28 static html widgets satisfying this $$, plus the dynamically added, 29th widget. When I then loop with the following, the loop apparently attempts to include the dynamically added widget. It successfully loops through the 28 pre-existing static html, then basically crashes on the first instruction inside the loop for the dynamically added 29th widget: widgetArray.each(function(widget) { alert("Beginning loop"); //crashes here Any help would be very much appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Ken Snyder
2007-Nov-28 23:14 UTC
Re: Odd Behavior of widgetArray.each and widgetArray.size()
BillT wrote:> ... > Specifically, there were 28 static html widgets satisfying this $$, > plus the dynamically added, 29th widget. > > When I then loop with the following, the loop apparently attempts to > include the dynamically added widget. It successfully loops through > the 28 pre-existing static html, then basically crashes on the first > instruction inside the loop for the dynamically added 29th widget: > > widgetArray.each(function(widget) { > alert("Beginning loop"); //crashes here > > Any help would be very much appreciated. >What kind of crash? Do you get an exception message? Are you waiting 10ms to allow the DOM tree to refresh? - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I found where the combination of $$ and IE7 breaks down in the series of nested HTML. Again, it works fine in Firefox in all conditions I have tested, and it works fine in IE7 for static HTML. Consider the following series of debugging statements: var debugTBodyTrArray = $$("#" + empTableId + " tbody tr"); var debugTBodyTrTdArray = $$("#" + empTableId + " tbody tr td"); var debugTBodyTrTdDivArray = $$("#" + empTableId + " tbody tr td div"); var debugTBodyTrTdDivInputArray = $$("#" + empTableId + " tbody tr td div input"); alert("debugTBodyTrArray.size before clone and insert: " + debugTBodyTrArray.size() ); alert("debugTBodyTrTdArray.size before clone and insert: " + debugTBodyTrTdArray.size() ); alert("debugTBodyTrTdDivArray.size before clone and insert: " + debugTBodyTrTdDivArray.size() ); alert("debugTBodyTrTdDivInputArray.size before clone and insert: " + debugTBodyTrTdDivInputArray.size() ); I then add a <TD> enclosing an <Input> to the DOM as follows: var clonedRow = rowArray[0].cloneNode(true); tbody.insertBefore(clonedRow, ptoRow); Then I revisit the series of debugging statements, as follows: var debugTBodyTrArray2 = $$("#" + empTableId + " tbody tr"); var debugTBodyTrTdArray2 = $$("#" + empTableId + " tbody tr td"); var debugTBodyTrTdDivArray2 = $$("#" + empTableId + " tbody tr td div"); var debugTBodyTrTdDivInputArray2 = $$("#" + empTableId + " tbody tr td div input"); //the problem occurs here !!! alert("debugTBodyTrArray2.size before clone and insert: " + debugTBodyTrArray2.size() ); alert("debugTBodyTrTdArray2.size before clone and insert: " + debugTBodyTrTdArray2.size() ); alert("debugTBodyTrTdDivArray2.size before clone and insert: " + debugTBodyTrTdDivArray2.size() ); alert("debugTBodyTrTdDivInputArray2.size before clone and insert: " + debugTBodyTrTdDivInputArray2.size() ); The number of tr''s, td''s, and div''s is reported to increase in this second set of statements, as they should. However, the reported number of input''s is improperly reported to be unchanged. The IE7 Developers Toolbar and the Firefox View Generated Source both show the same <input> nested within the <div>, which is nested within the <td>, as follows: <TD class="middle_cell_style" noWrap height="23"> <DIV align="center"> <INPUT class="emp1Time" id="emp1SatPer3Start" readOnly maxLength="8" size="7" name="emp1SatPer3End" _counted="undefined" value="" /> </DIV> </TD> Bill ------------------------------------------------------------- On Nov 28, 6:14 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BillT wrote: > > ... > > Specifically, there were 28 static html widgets satisfying this $$, > > plus the dynamically added, 29th widget. > > > When I then loop with the following, the loop apparently attempts to > > include the dynamically added widget. It successfully loops through > > the 28 pre-existing static html, then basically crashes on the first > > instruction inside the loop for the dynamically added 29th widget: > > > widgetArray.each(function(widget) { > > alert("Beginning loop"); //crashes here > > > Any help would be very much appreciated. > > What kind of crash? Do you get an exception message? Are you waiting > 10ms to allow the DOM tree to refresh? > > - Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---