...

View Full Version : Align a button in Javascript



danielgeorgy
11-06-2012, 06:52 AM
Hello,
I am very new to Javascript and other web related stuff.
I am trying to align a button in a javascript file,

The button is defined in an erb file like this

<div id="button1" class="arial buttonprop ten right">CLICK ME ></div>

In another javascript file user hides and shows this button
$('#button1').hide();
$('#button1').show();

Is it possible to allign the button to left right or center in this Javascript file.

Thanks,
Georgy

Dormilich
11-06-2012, 08:08 AM
even in JavaScript, alignment of HTML elements is done through CSS, for which the jQuery library offers some methods (e.g. .css()).

felgall
11-06-2012, 09:52 PM
even in JavaScript, alignment of HTML elements is done through CSS, for which the jQuery library offers some methods (e.g. .css()).

You don't even need to use jQuery to interact with CSS as JavaScript itself offers even more ways to do so - eg. .cssText()

danielgeorgy
11-07-2012, 08:01 AM
Thanks Guys...

I used the .css() function, i could able to do these things like

1) float : left/right ---- for left/right alignment

2) margin-left : value
margin-right : value
This also is good for left/right alignment

But for aligning to the center i tried

margin-left : auto
margin-right : auto

it doesn't seems to be working.

So Is there any other way to align the button to the center

Thanks
Georgy


You don't even need to use jQuery to interact with CSS as JavaScript itself offers even more ways to do so - eg. .cssText()

Dormilich
11-07-2012, 08:02 AM
IIRC, the margin:auto trick only works on block elements.

felgall
11-07-2012, 07:44 PM
IIRC, the margin:auto trick only works on block elements.

Yes - to centre text you can use text-align:center

It doesn't make sense to try to centre any other inline elements as they all take up exactly as much width as they need and so are already centred in that width.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum