# How set background image inside \<td \> tag dynamically

**URL:** <https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758>\
**Category:** Rails\
**Created:** [January 29, 2007, 3:51pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758 "2007-01-29T15:51:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijayendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@vijayendra](https://www.ruby-forum.com/u/vijayendra)\
**Post date:** [January 29, 2007, 3:51pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758/1 "2007-01-29T15:51:35Z")

</div>

how set background image inside

 tag dynamically - plz help me

---

<div class="post-metadata">

**Author:** ![vijayendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@vijayendra](https://www.ruby-forum.com/u/vijayendra)\
**Post date:** [January 29, 2007, 4:03pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758/2 "2007-01-29T16:03:37Z")

</div>

Vijayendra A. wrote:

> how set background image inside tag dynamically - plz help me

Statically, it’s like style =  
“background-image:url(/images/wiki/skyRamp.png)”

Dynamically, it might be page[‘td\_id’][‘style’].backgroundImage =  
“url(…)”

Someone should check my JavaScriptGenerator syntax, but that’s where I  
would start…

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![vijayendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@vijayendra](https://www.ruby-forum.com/u/vijayendra)\
**Post date:** [January 29, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758/3 "2007-01-29T16:13:47Z")

</div>

Phlip wrote:

> Vijayendra A. wrote:
> 
> > how set background image inside tag dynamically - plz help me
> 
> Statically, it’s like style =  
> “background-image:url(/images/wiki/skyRamp.png)”
> 
> Dynamically, it might be page[‘td\_id’][‘style’].backgroundImage =  
> “url(…)”
> 
> Someone should check my JavaScriptGenerator syntax, but that’s where I  
> would start…
> 
> –  
> Phlip  
> [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

if i wanted to code this insdie \<%= %\> how to code

---

<div class="post-metadata">

**Author:** ![vijayendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@vijayendra](https://www.ruby-forum.com/u/vijayendra)\
**Post date:** [January 29, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758/4 "2007-01-29T16:26:41Z")

</div>

Vijayendra A. wrote:

> if i wanted to code this insdie \<%= %\> how to code

Oh, that kind of “dynamic”!

Here’s my output:

(I built that with Builder::XmlMarkup, not ERb. Don’t try that until  
you learn more programming!)

Now you can put the \<%= %\> anywhere in there that you like, replacing  
as much or as little of the source as you need, so long as ERb can  
read it and generate well-formed HTML.

To vary just the image itself, try this:

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![vijayendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@vijayendra](https://www.ruby-forum.com/u/vijayendra)\
**Post date:** [January 29, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758/5 "2007-01-29T17:28:14Z")

</div>

thanks

but its not working

Phlip wrote:

> Vijayendra A. wrote:
> 
> > if i wanted to code this insdie \<%= %\> how to code
> 
> Oh, that kind of “dynamic”!
> 
> Here’s my output:
> 
> (I built that with Builder::XmlMarkup, not ERb. Don’t try that until  
> you learn more programming!)
> 
> Now you can put the \<%= %\> anywhere in there that you like, replacing  
> as much or as little of the source as you need, so long as ERb can  
> read it and generate well-formed HTML.
> 
> To vary just the image itself, try this:
> 
> –  
> Phlip  
> [http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![vijayendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a87d85/32.png) [@vijayendra](https://www.ruby-forum.com/u/vijayendra)\
**Post date:** [January 29, 2007, 5:48pm UTC](https://www.ruby-forum.com/t/how-set-background-image-inside-td-tag-dynamically/83758/6 "2007-01-29T17:48:17Z")

</div>

Vijayendra A. wrote:

> thanks
> 
> but its not working

Start a new thread with a new subject line, and post your code here.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!
