2

I want to apply more than 1 CSS styles to the button (its id is name_button).

Here is my javaScript code.

var name_button = document.getElementById('name_button');
name_button.style.display = 'block';
name_button.style.margin-left = '125px';
name_button.style.padding-right = '0px';

But with the last two lines (name_button.style.margin-left = '125px'; and name_button.style.padding-right = '0px';) my code is not working.

Nanga
  • 73
  • 2
  • 7
  • 1
    You are using wrong style properties. Refer this for correct naming http://www.w3schools.com/jsref/dom_obj_style.asp. – Ateev Chopra Jan 14 '15 at 07:24
  • You can set a class having properties, and when you click add a class to a that button. – Swapnil Motewar Jan 14 '15 at 07:35
  • 1
    use like below 'name_button.style.marginLeft = '125px';' 'name_button.style.paddingRight = '0px';' – Amare Jan 14 '15 at 07:36
  • (Using Chrome) If you select an element then right-click and select "Inspect Element", you'll get the element selected in the element inspector. If you then select the `Properties` tab, and then open the first item in the list, you can browse down to the `style` property. Opening that shows you the list of valid attributes that the element has. You can also use this approach to discover other types of info about various elements. This can be handy if you're away from the net and don't have a reference handy. – enhzflep Jan 14 '15 at 07:52

2 Answers2

3

In JavaScript all css values with - are camel cased. so:

name_button.style.margin-left = '125px';

Becomes:

name_button.style.marginLeft = '125px';

and

name_button.style.padding-right = '0px';

becomes:

name_button.style.paddingRight = '0px';
Bogdan Kuštan
  • 5,427
  • 1
  • 21
  • 30
1

try this

name_button.style.marginLeft = "50px";
Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71