From: Don on
I need to dynamically change a rule's "margin-top", but I get a JS error on the following. JS doesn't seem to like the hyphen in "margin-top". It works for other style properities, e.g., "width".

document.styleSheets[0].rules[7].style.margin-top = "200";

Thanks for your help.
Don
From: Don on
On Fri, 30 Jul 2010 21:16:42 +0100, Tim Streater <timstreater(a)waitrose.com> wrote:

>In article <timstreater-C27E63.21130730072010(a)news.individual.net>,
> Tim Streater <timstreater(a)waitrose.com> wrote:
>
>> In article <1tb6569c4mgtojagnjthf8v95jh18gcfun(a)4ax.com>,
>> Don <no(a)adr.com> wrote:
>>
>> > I need to dynamically change a rule's "margin-top", but I get a JS error on
>> > the following. JS doesn't seem to like the hyphen in "margin-top". It
>> > works
>> > for other style properities, e.g., "width".
>> >
>> > document.styleSheets[0].rules[7].style.margin-top = "200";
>
>By the way that's not a hyphen. It's a minus sign which is why JS is
>bleating.
I thought a "minus-sign" had the same character-code as a "hyphen".
From: Don on
On Fri, 30 Jul 2010 21:13:07 +0100, Tim Streater <timstreater(a)waitrose.com> wrote:

>In article <1tb6569c4mgtojagnjthf8v95jh18gcfun(a)4ax.com>,
> Don <no(a)adr.com> wrote:
>
>> I need to dynamically change a rule's "margin-top", but I get a JS error on
>> the following. JS doesn't seem to like the hyphen in "margin-top". It works
>> for other style properities, e.g., "width".
>>
>> document.styleSheets[0].rules[7].style.margin-top = "200";
>
>If you google for margin-top you'll probably find a site that tells you
>the equivalence between the CSS atttribute and the JavaScript
>equivalent. Such as:
>
>document.styleSheets[0].rules[7].style.marginTop = 200 + "px";


That works! I've spent the past hour on this, googling and experimenting. I thought I tried "marginTop", but maybe I didn't. Some days are just a bear!
Thanks, for your help Tim. I appreciate it!

Don
From: David Mark on
On Jul 30, 4:16 pm, Tim Streater <timstrea...(a)waitrose.com> wrote:
> In article <timstreater-C27E63.21130730072...(a)news.individual.net>,
>  Tim Streater <timstrea...(a)waitrose.com> wrote:
>
> > In article <1tb6569c4mgtojagnjthf8v95jh18gc...(a)4ax.com>,
> >  Don <n...(a)adr.com> wrote:
>
> > > I need to dynamically change a rule's "margin-top", but I get a JS error on
> > > the following.  JS doesn't seem to like the hyphen in "margin-top".  It
> > > works
> > > for other style properities, e.g., "width".
>
> > > document.styleSheets[0].rules[7].style.margin-top = "200";
>
> By the way that's not a hyphen. It's a minus sign which is why JS is
> bleating.
>

Just to avert confusion, it's a minus sign that works in CSS and a
hyphen character would work for neither.

From: Don on
On Fri, 30 Jul 2010 21:45:10 +0100, Tim Streater <timstreater(a)waitrose.com> wrote:

>In article <n4d656p1rncc97o07bqc0k7ph17h7ik5st(a)4ax.com>,
> Don <no(a)adr.com> wrote:
>
>> On Fri, 30 Jul 2010 21:16:42 +0100, Tim Streater <timstreater(a)waitrose.com>
>> wrote:
>>
>> >In article <timstreater-C27E63.21130730072010(a)news.individual.net>,
>> > Tim Streater <timstreater(a)waitrose.com> wrote:
>> >
>> >> In article <1tb6569c4mgtojagnjthf8v95jh18gcfun(a)4ax.com>,
>> >> Don <no(a)adr.com> wrote:
>> >>
>> >> > I need to dynamically change a rule's "margin-top", but I get a JS error
>> >> > on
>> >> > the following. JS doesn't seem to like the hyphen in "margin-top". It
>> >> > works
>> >> > for other style properities, e.g., "width".
>> >> >
>> >> > document.styleSheets[0].rules[7].style.margin-top = "200";
>> >
>> >By the way that's not a hyphen. It's a minus sign which is why JS is
>> >bleating.
>> I thought a "minus-sign" had the same character-code as a "hyphen".
>
>I mean to say that JS knows nothing about hyphens and plenty about
>minus-signs.
>
>:-)

Okay. Thanks to all for your help.

Don