Get img from cell in Firefox

Hello all!

I'm trying to change the src of imgs in 5 different cells so I iterate
through the cells in the table and do this:
var img = table.rows[0].cells[n].firstChild;
img.src = some url

This works fine in IE but not in any other browser. What's the trick here?

Thanks,
Joe
joe [ Mi, 02 April 2008 22:30 ] [ ID #1933715 ]

Re: Get img from cell in Firefox

Actually I guess it's rendered as an input. I'm using ImageButtons that I'm
trying to change.

"Joe" <jbassking [at] noemail.noemail> wrote in message
news:exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl...
> Hello all!
>
> I'm trying to change the src of imgs in 5 different cells so I iterate
> through the cells in the table and do this:
> var img = table.rows[0].cells[n].firstChild;
> img.src = some url
>
> This works fine in IE but not in any other browser. What's the trick here?
>
> Thanks,
> Joe
>
joe [ Mi, 02 April 2008 22:47 ] [ ID #1933716 ]

Re: Get img from cell in Firefox

Now it looks like my problem is I cannot get/set the title.

"Joe" <jbassking [at] noemail.noemail> wrote in message
news:exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl...
> Hello all!
>
> I'm trying to change the src of imgs in 5 different cells so I iterate
> through the cells in the table and do this:
> var img = table.rows[0].cells[n].firstChild;
> img.src = some url
>
> This works fine in IE but not in any other browser. What's the trick here?
>
> Thanks,
> Joe
>
joe [ Mi, 02 April 2008 23:30 ] [ ID #1933723 ]

Re: Get img from cell in Firefox

Hi Joe,

As for loop through all the image(or other html elements in a html table),
I would suggeest you use the "document.getElementByTagName" function as
it's the standard DOM interface which works on both IE and firebox. The "
table.rows[0].cells[n].firstChild;" syntax is somewhat coupled with IE
browser. Here is a simple test page demonstrate this:

===========================================
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function get_img_in_table(tbid)
{
var tb = document.getElementById(tbid);

var imgs = document.getElementsByTagName("IMG");

var i =0;

for(i=0;i<imgs.length;++i)
{
alert(imgs[i].src);
imgs[i].alt = imgs[i].src;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="tbImages" >
<tr>
<td>image:</td>
<td><img
src="http://www.asp.net/App_Themes/Standard/i/logo.png" /></td>
</tr>

<tr>
<td>image:</td>
<td><img
src="http://static.asp.net/asp.net/images/books/book13.gif" /></td>
</tr>

<tr>
<td>image:</td>
<td><img src="http://ads.asp.net/ads/200_50_aspnet_gr.gif"
/></td>
</tr>
</table>



<input type="button" value="get image in table"
onclick="get_img_in_table('tbImages');" />
</div>
</form>
</body>
==============================================

BTW, for your new question about setting the "title", would you tell me
what' the title you mentioned? is it the page title or title of some other
html element on page?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg [at] microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Joe" <jbassking [at] noemail.noemail>
>References: <exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl>
>Subject: Re: Get img from cell in Firefox
>Date: Wed, 2 Apr 2008 17:30:30 -0400
>
>Now it looks like my problem is I cannot get/set the title.
>
>"Joe" <jbassking [at] noemail.noemail> wrote in message
>news:exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl...
>> Hello all!
>>
>> I'm trying to change the src of imgs in 5 different cells so I iterate
>> through the cells in the table and do this:
>> var img = table.rows[0].cells[n].firstChild;
>> img.src = some url
>>
>> This works fine in IE but not in any other browser. What's the trick
here?
>>
>> Thanks,
>> Joe
>>
>
>
>
stcheng [ Do, 03 April 2008 05:15 ] [ ID #1934521 ]

Re: Get img from cell in Firefox

On 2 =D0=9A=D0=B2=D1=96, 23:30, "Joe" <jbassk... [at] noemail.noemail> wrote:
> Hello all!
>
> I'm trying to change the src of imgs in 5 different cells so I iterate
> through the cells in the table and do this:
> var img =3D table.rows[0].cells[n].firstChild;
> img.src =3D some url
>
> This works fine in IE but not in any other browser. What's the trick here?=

>
> Thanks,
> Joe

Hi Joe,

Little addition to the Steven's post.
document.getElementsByTagName("IMG") returns all images on a page.
table, tr, td elements also have getElementsByTagName method and you
can reduce result images set if you use it.

Regarding of firstChild.
In Firefox it depends on HTML structure, if there is a gap between td
and img tags then the first child is a text node.
1. <td><img ... - firstChild is image
2. <td> <img ... - firstChild is text node

Regards,
Mykola
http://marss.co.ua
marss [ Do, 03 April 2008 07:39 ] [ ID #1934528 ]

Re: Get img from cell in Firefox

The getElemenetByTagName worked to fix my issue. Thanks.

"Steven Cheng [MSFT]" <stcheng [at] online.microsoft.com> wrote in message
news:eDhGNvTlIHA.4932 [at] TK2MSFTNGHUB02.phx.gbl...
> Hi Joe,
>
> As for loop through all the image(or other html elements in a html table),
> I would suggeest you use the "document.getElementByTagName" function as
> it's the standard DOM interface which works on both IE and firebox. The "
> table.rows[0].cells[n].firstChild;" syntax is somewhat coupled with IE
> browser. Here is a simple test page demonstrate this:
>
> ===========================================
> <head runat="server">
> <title>Untitled Page</title>
> <script type="text/javascript">
> function get_img_in_table(tbid)
> {
> var tb = document.getElementById(tbid);
>
> var imgs = document.getElementsByTagName("IMG");
>
> var i =0;
>
> for(i=0;i<imgs.length;++i)
> {
> alert(imgs[i].src);
> imgs[i].alt = imgs[i].src;
> }
> }
> </script>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <table id="tbImages" >
> <tr>
> <td>image:</td>
> <td><img
> src="http://www.asp.net/App_Themes/Standard/i/logo.png" /></td>
> </tr>
>
> <tr>
> <td>image:</td>
> <td><img
> src="http://static.asp.net/asp.net/images/books/book13.gif" /></td>
> </tr>
>
> <tr>
> <td>image:</td>
> <td><img src="http://ads.asp.net/ads/200_50_aspnet_gr.gif"
> /></td>
> </tr>
> </table>
>
>

> <input type="button" value="get image in table"
> onclick="get_img_in_table('tbImages');" />
> </div>
> </form>
> </body>
> ==============================================
>
> BTW, for your new question about setting the "title", would you tell me
> what' the title you mentioned? is it the page title or title of some other
> html element on page?
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg [at] microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx .
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> --------------------
>>From: "Joe" <jbassking [at] noemail.noemail>
>>References: <exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl>
>>Subject: Re: Get img from cell in Firefox
>>Date: Wed, 2 Apr 2008 17:30:30 -0400
>>
>>Now it looks like my problem is I cannot get/set the title.
>>
>>"Joe" <jbassking [at] noemail.noemail> wrote in message
>>news:exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl...
>>> Hello all!
>>>
>>> I'm trying to change the src of imgs in 5 different cells so I iterate
>>> through the cells in the table and do this:
>>> var img = table.rows[0].cells[n].firstChild;
>>> img.src = some url
>>>
>>> This works fine in IE but not in any other browser. What's the trick
> here?
>>>
>>> Thanks,
>>> Joe
>>>
>>
>>
>>
>
joe [ Do, 03 April 2008 18:06 ] [ ID #1934576 ]

Re: Get img from cell in Firefox

Thanks for your reply Joe,

I'm glad that it helps you.

Have a nice day!

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg [at] microsoft.com.
========================================
>From: "Joe" <jbassking [at] noemail.noemail>
>References: <exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl>
<OV7RUkQlIHA.484 [at] TK2MSFTNGP04.phx.gbl>
<eDhGNvTlIHA.4932 [at] TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: Get img from cell in Firefox
>Date: Thu, 3 Apr 2008 12:06:39 -0400

>
>The getElemenetByTagName worked to fix my issue. Thanks.
>
>"Steven Cheng [MSFT]" <stcheng [at] online.microsoft.com> wrote in message
>news:eDhGNvTlIHA.4932 [at] TK2MSFTNGHUB02.phx.gbl...
>> Hi Joe,
>>
>> As for loop through all the image(or other html elements in a html
table),
>> I would suggeest you use the "document.getElementByTagName" function as
>> it's the standard DOM interface which works on both IE and firebox. The "
>> table.rows[0].cells[n].firstChild;" syntax is somewhat coupled with IE
>> browser. Here is a simple test page demonstrate this:
>>
>> ===========================================
>> <head runat="server">
>> <title>Untitled Page</title>
>> <script type="text/javascript">
>> function get_img_in_table(tbid)
>> {
>> var tb = document.getElementById(tbid);
>>
>> var imgs = document.getElementsByTagName("IMG");
>>
>> var i =0;
>>
>> for(i=0;i<imgs.length;++i)
>> {
>> alert(imgs[i].src);
>> imgs[i].alt = imgs[i].src;
>> }
>> }
>> </script>
>> </head>
>> <body>
>> <form id="form1" runat="server">
>> <div>
>> <table id="tbImages" >
>> <tr>
>> <td>image:</td>
>> <td><img
>> src="http://www.asp.net/App_Themes/Standard/i/logo.png" /></td>
>> </tr>
>>
>> <tr>
>> <td>image:</td>
>> <td><img
>> src="http://static.asp.net/asp.net/images/books/book13.gif" /></td>
>> </tr>
>>
>> <tr>
>> <td>image:</td>
>> <td><img src="http://ads.asp.net/ads/200_50_aspnet_gr.gif"
>> /></td>
>> </tr>
>> </table>
>>
>>

>> <input type="button" value="get image in table"
>> onclick="get_img_in_table('tbImages');" />
>> </div>
>> </form>
>> </body>
>> ==============================================
>>
>> BTW, for your new question about setting the "title", would you tell me
>> what' the title you mentioned? is it the page title or title of some
other
>> html element on page?
>>
>> Sincerely,
>>
>> Steven Cheng
>>
>> Microsoft MSDN Online Support Lead
>>
>>
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.
Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> msdnmg [at] microsoft.com.
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>>
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
>> ications.
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/default.aspx .
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> --------------------
>>>From: "Joe" <jbassking [at] noemail.noemail>
>>>References: <exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl>
>>>Subject: Re: Get img from cell in Firefox
>>>Date: Wed, 2 Apr 2008 17:30:30 -0400
>>>
>>>Now it looks like my problem is I cannot get/set the title.
>>>
>>>"Joe" <jbassking [at] noemail.noemail> wrote in message
>>>news:exTjkCQlIHA.1188 [at] TK2MSFTNGP04.phx.gbl...
>>>> Hello all!
>>>>
>>>> I'm trying to change the src of imgs in 5 different cells so I iterate
>>>> through the cells in the table and do this:
>>>> var img = table.rows[0].cells[n].firstChild;
>>>> img.src = some url
>>>>
>>>> This works fine in IE but not in any other browser. What's the trick
>> here?
>>>>
>>>> Thanks,
>>>> Joe
>>>>
>>>
>>>
>>>
>>
>
>
>
stcheng [ Fr, 04 April 2008 04:49 ] [ ID #1935371 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Get img from cell in Firefox

Vorheriges Thema: How to populate a field in gridview with data FROM ANOTHER TABLE?
Nächstes Thema: navigation question using TabContainer-ajax control