Hi,

> Hi Crowder,

LOL -- so no one else on the list is allowed to answer? ;-)

> var tdElem = this.containerElement.getElementsByTagName("td");
> var colItem = tdElem.item(0);
> var colWidth = colItem.style.width;
> var colWidth = (col.item(0)).getWidth(); // not working in IE.  It is dying.

That's because on IE, Prototype can't automagically extend elements.
You have to explicitly extend them by passing them through `$`, or
retrieve them via Prototype (which will extend them for you before
giving them to you). In the code above, you've used raw DOM methods to
get the NodeList and get the Element from it, so it doesn't have
Prototype's syntactic sugar. More here:
http://prototypejs.org/learn/extensions

Or to put all that another way, try this:

var tdElem = this.containerElement.select("td");
//Or var tdElem = $(this.containerElement).select("td"); if
this.containerElement hasn't
//already been extended
var colItem = tdElem[0];
var colWidth = colItem.getWidth();

or this:

var tdElem = this.containerElement.getElementsByTagName("td");
var colItem = tdElem.item(0);
var colWidth = $(col.item(0)).getWidth();
            // ^-- change is here

> var colWidth = $$('td').getWidth();  // Not working if the table is created
> dynamically

That won't work regardless of whether the table was created
dynamically or not. `$$` returns an Array, not an Element, and arrays
don't have a `getWidth` function. You'd need something like this (for
the first one):
var colwidth = $$('td')[0].getWidth();

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Sep 21, 2:41 pm, Somdatta Nath <nath.somda...@gmail.com> wrote:
> Hi Crowder,
>
> I am having some problem in implementing a dynamic table and getting the
> width of an td element in IE (Safari, FF works ok.)
> I am creating the table as :
>
> var myTable = document.createElement("table");
>
> var myThead = document.createElement("thead");
> var myTfoot = document.createElement("tfoot");
>
> var myTbody = document.createElement("tbody");
>
> var myRow = document.createElement("tr");
>
> var myCell = document.createElement("td");
>
> myTable.appendChild(myThead);
> myTable.appendChild(myTfoot);
>
> myTable.appendChild(myTbody);
>
> myTbody.appendChild(myRow);
>
> myRow.appendChild(myCell);
>
> this.containerElement.appendChild(myTable);
>
> -------------------------------
>
> I have a css file where I set up the style for the td element.
>
> td.one
> {
> height:80px;
> width:80px;
>  border: 1px solid #000;
>  background:#333;
>
> vertical-align:middle;
> voice-family: "\"}\"";
> voice-family: inherit;
> width: 78px; }
>
> td { width:78px; } ,
>
> ----------------------
>
> After running the the code, I could see that the table with one cell is
> getting created correctly.  But if I try to get width, I am not getting
> anything.
>
> However, if I create the table in a static html code.  At least I can query
> the element by :
>
> var tdElem = this.containerElement.getElementsByTagName("td");
>
> var colItem = tdElem.item(0);
>
> var colWidth = colItem.style.width;
>
> var colWidth = (col.item(0)).getWidth(); // not working in IE.  It is dying.
>
> var colWidth = $$('td').getWidth();  // Not working if the table is created
> dynamically
>
> ------------------------
>
> This probably already an discussed topic.  I am wondering why is this
> difference between statically and dynamically created table ?  Is there a
> way to get width of the td element (created dynamically) that works in IE?
>  I do not have any problem in getting getWidth() working for dynamically
> created table in FF and Safari.
>
> Any help is appreciated.
>
> Thanks so much,

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to