Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change "margin-top" using JS

1 view
Skip to first unread message

Don

unread,
Jul 30, 2010, 4:04:31 PM7/30/10
to
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

Message has been deleted
Message has been deleted

Don

unread,
Jul 30, 2010, 4:23:38 PM7/30/10
to
On Fri, 30 Jul 2010 21:16:42 +0100, Tim Streater <timst...@waitrose.com> wrote:

>In article <timstreater-C27E...@news.individual.net>,
> Tim Streater <timst...@waitrose.com> wrote:
>
>> In article <1tb6569c4mgtojagn...@4ax.com>,

>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".

Don

unread,
Jul 30, 2010, 4:24:29 PM7/30/10
to
On Fri, 30 Jul 2010 21:13:07 +0100, Tim Streater <timst...@waitrose.com> wrote:

>In article <1tb6569c4mgtojagn...@4ax.com>,
> Don <n...@adr.com> wrote:
>

>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

David Mark

unread,
Jul 30, 2010, 4:28:30 PM7/30/10
to
On Jul 30, 4:16 pm, Tim Streater <timstrea...@waitrose.com> wrote:
> In article <timstreater-C27E63.21130730072...@news.individual.net>,
>  Tim Streater <timstrea...@waitrose.com> wrote:
>
> > In article <1tb6569c4mgtojagnjthf8v95jh18gc...@4ax.com>,
> 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.

Message has been deleted

Don

unread,
Jul 30, 2010, 4:59:26 PM7/30/10
to
On Fri, 30 Jul 2010 21:45:10 +0100, Tim Streater <timst...@waitrose.com> wrote:

>In article <n4d656p1rncc97o07...@4ax.com>,

>I mean to say that JS knows nothing about hyphens and plenty about
>minus-signs.
>
>:-)

Okay. Thanks to all for your help.

Don

Denis McMahon

unread,
Jul 30, 2010, 5:52:21 PM7/30/10
to
On 30/07/10 21:23, Don wrote:

> I thought a "minus-sign" had the same character-code as a "hyphen".

In javascript, if it's not in quotes, it's a minus sign.

If it is in quotes, you can call it minus or hyphen or dash or whatever
else you like.

Rgds

Denis McMahon

Luuk

unread,
Jul 30, 2010, 7:04:05 PM7/30/10
to
Op 30-07-10 22:24, Don schreef:

than you need a crash-course in Google:

http://lmgtfy.com/?q=css+margin+top+javascript&l=1

1st link is going to:
http://www.w3schools.com/css/pr_margin-top.asp

and there's the info about "margintop".......

--
Luuk

John G Harris

unread,
Jul 31, 2010, 12:48:00 PM7/31/10
to
On Fri, 30 Jul 2010 at 13:23:38, in comp.lang.javascript, Don wrote:
>On Fri, 30 Jul 2010 21:16:42 +0100, Tim Streater

<snip>


>>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".

No. ASCII has a minus sign. A hyphen is longer and ASCII doesn't have
one.

John
--
John Harris

Hans-Georg Michna

unread,
Jul 31, 2010, 1:45:00 PM7/31/10
to
On Fri, 30 Jul 2010 13:23:38 -0700, Don wrote:

> I thought a "minus-sign" had the same character-code as a "hyphen".

Far from it. Check http://www.cs.tut.fi/~jkorpela/dashes.html
for more info.

Hans-Georg

Jukka K. Korpela

unread,
Jul 31, 2010, 2:01:20 PM7/31/10
to
Under Subject: Re: How to change "margin-top" using JS
John G Harris wrote:

> On Fri, 30 Jul 2010 at 13:23:38, in comp.lang.javascript, Don wrote:
>> On Fri, 30 Jul 2010 21:16:42 +0100, Tim Streater
>
> <snip>
>>> 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".
>
> No. ASCII has a minus sign.

I have actually bought and read the ASCII standard (ANSI INCITS 4-1986), so
I know what I'm talking about. It has a character with the primary name
HYPHEN and the alternate name MINUS SIGN. In Unicode, this character is
called HYPHEN-MINUS to reflect its semantic ambiguity: it is used as a
hyphen, as a minus sign, as an en dash, as en em dash, and for other
purposes. Unicode additionally encodes, in different positions, the
unambiguous (or at least less ambiguous) characters HYPHEN and MINUS SIGN,
but in ASCII, you cannot make such a distinction.

Of course, in JavaScript and relatives, as in most programming languages,
the ASCII HYPHEN character has, by definition, the semantics of a minus sign
when used in an arithmetic expression. But this relates to the "higher level
protocol", the language definition, and not to character-level issues.

> A hyphen is longer and ASCII doesn't have one.

Wrong. ASCII has HYPHEN just as well as it has MINUS SIGN, or more (since
HYPHEN is the primary name). When a distinction is made between a hyphen and
a minus sign, the minus sign is surely longer. The length (width) of ASCII
HYPHEN varies by font, since its design may reflect the primary use as a
hyphen, where it should be fairly short by typographic tradition, or the
ambiguous semantics (so that the length is between the length of a
typographically suitable hyphen and the length of a typographically suitable
minus sign or en dash or em dash).

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Dr J R Stockton

unread,
Jul 31, 2010, 6:13:09 PM7/31/10
to
In comp.lang.javascript message <timstreater-5DDBF9.21451030072010@news.
individual.net>, Fri, 30 Jul 2010 21:45:10, Tim Streater
<timst...@waitrose.com> posted:

>
>I mean to say that JS knows nothing about hyphens and plenty about
>minus-signs.

IIRC, without checking at www.unicode.org, Unicode has a character
position for minus and another for hyphen. Computer programmers and
most typists use neither of those, but use \x2D which is generated by a
keyboard key directly.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 7.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

Hans-Georg Michna

unread,
Aug 1, 2010, 5:30:00 AM8/1/10
to

But as the author is right here, you might as well ask him
directly. (:-)

Hans-Georg

0 new messages