$(element).setStyle({
background: ''url(/image.gif) no-repeat'' /* Myproblem:
background: ''someVariable'' */
});
The above code snippet assigns the value ''url(image.gif)
no-repeat'' to
the property ''background''. I have a situation where in i am
getting
the value i.e image URL from the back-end dynamically and i am able to
store it in a variable say ''someVariable''. Now what is the
syntax I
should follow to assign ''someVariable'' to background. Please
help.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
bram.vandersype-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-03 14:06 UTC
Re: How to assign a variable as value to a property
var bg = ''background: url('' + someVariable + '')
no-repeat;'';
$(element).setStyle(bg);
that should do the trick.
On Jan 3, 2:27 pm, yash
<itsme.y...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> $(element).setStyle({
> background: ''url(/image.gif) no-repeat'' /*
Myproblem:
> background: ''someVariable'' */
>
> });
>
> The above code snippet assigns the value ''url(image.gif)
no-repeat'' to
> the property ''background''. I have a situation where in i
am getting
> the value i.e image URL from the back-end dynamically and i am able to
> store it in a variable say ''someVariable''. Now what is
the syntax I
> should follow to assign ''someVariable'' to background.
Please help.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Thanks for the reply. The var bg is getting constructed correctly but $ (element).setStyle(bg); does not work. Is there any particular way of accessing variables?? On Jan 3, 7:06 pm, "bram.vanders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <bram.vanders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> var bg = ''background: url('' + someVariable + '') no-repeat;''; > $(element).setStyle(bg); > > that should do the trick. > > On Jan 3, 2:27 pm, yash <itsme.y...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > $(element).setStyle({ > > background: ''url(/image.gif) no-repeat'' /* Myproblem: > > background: ''someVariable'' */ > > > }); > > > The above code snippet assigns the value ''url(image.gif) no-repeat'' to > > the property ''background''. I have a situation where in i am getting > > the value i.e image URL from the back-end dynamically and i am able to > > store it in a variable say ''someVariable''. Now what is the syntax I > > should follow to assign ''someVariable'' to background. Please help.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
zuzmic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-04 08:36 UTC
Re: How to assign a variable as value to a property
Im not sure, but better use ''background-repeat'' and ''background- color'' yash wrote:> $(element).setStyle({ > background: ''url(/image.gif) no-repeat'' /* Myproblem: > background: ''someVariable'' */ > }); > > The above code snippet assigns the value ''url(image.gif) no-repeat'' to > the property ''background''. I have a situation where in i am getting > the value i.e image URL from the back-end dynamically and i am able to > store it in a variable say ''someVariable''. Now what is the syntax I > should follow to assign ''someVariable'' to background. Please help.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 3, 11:27 pm, yash <itsme.y...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> $(element).setStyle({ > background: ''url(/image.gif) no-repeat'' /* Myproblem: > background: ''someVariable'' */ > > }); > > The above code snippet assigns the value ''url(image.gif) no-repeat'' to > the property ''background''. I have a situation where in i am getting > the value i.e image URL from the back-end dynamically and i am able to > store it in a variable say ''someVariable''. Now what is the syntax I > should follow to assign ''someVariable'' to background. Please help.Just assign it: element.style.background = ''url('' + imgSrc + '') no-repeat''; or if you really want to use setStyle: $(element).setStyle({ ''background'': ''url('' + imgSrc + '') no-repeat'' }); <URL: http://www.prototypejs.org/api/element/setStyle > -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The below code snippet works.Cheers...
$(element).setStyle({
''background: ''url('' + imgSrc + '')
no-repeat''
});
The one thing I learnt from this is to treat javascript more as a
scripting language and less as a programing language.
On Jan 4, 2:31 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org>
wrote:> On Jan 3, 11:27 pm, yash
<itsme.y...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > $(element).setStyle({
> > background: ''url(/image.gif) no-repeat'' /*
Myproblem:
> > background: ''someVariable'' */
>
> > });
>
> > The above code snippet assigns the value ''url(image.gif)
no-repeat'' to
> > the property ''background''. I have a situation where
in i am getting
> > the value i.e image URL from the back-end dynamically and i am able to
> > store it in a variable say ''someVariable''. Now what
is the syntax I
> > should follow to assign ''someVariable'' to
background. Please help.
>
> Just assign it:
>
> element.style.background = ''url('' + imgSrc +
'') no-repeat'';
>
> or if you really want to use setStyle:
>
> $(element).setStyle({
> ''background'': ''url('' + imgSrc +
'') no-repeat''
> });
>
> <URL:http://www.prototypejs.org/api/element/setStyle>
>
> --
> Rob
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Nicolás Sanguinetti
2008-Jan-07 14:02 UTC
Re: How to assign a variable as value to a property
On Jan 7, 2008 10:50 AM, yash <itsme.yash-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The one thing I learnt from this is to treat javascript more as a > scripting language and less as a programing language.The difference being? -Nicolas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 7, 10:50 pm, yash <itsme.y...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The below code snippet works.Cheers... > $(element).setStyle({ > ''background: ''url('' + imgSrc + '') no-repeat'' > });No it doesn''t, it has a syntax error. I would expect setStyle to be used only where you don''t know what style property is to be set, and even then only if you expect to have to deal with opacity or float properties. If you know the property you want to set, I can''t see the point in using setStyle over just setting the attribute value (which is more efficient and slightly less code to write). The first time you have to sift through the code to modify styles you may come to the conclusion that you should give the element a class and let a CSS guru do the work.> The one thing I learnt from this is to treat javascript more as a > scripting language and less as a programing language.From the perspective of the author, there is no difference. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---