Jump to content

Setattribute Preferred But What About Style Elements?


nachumk
 Share

Recommended Posts

Is there a more appropriate way to set just a single style attribute? I want to bold an element which has a previous style already set. Currently I use input.style.fontWeight. Feels like the only correct way to do this, but I am wondering whether this is the correct way?Perhaps a function like setSubAttribute?Could you also explain why fontWeight is font-weight sometimes? What's the rule for those naming conventions? The string for style contains font-weight, the setAttribute requires font-weight, and the input.style.fontWeight is correct.Thanx,

Link to comment
Share on other sites

When setting the style, don't use setAttribute().In Javascript, The '-' symbol is an operator. Writing "font-weight" would be like subtracting the value of weight from the font property of the object.In Javascript, any property that has a '-' will be changed so that the '-' is gone and the first letter of the next word is capitalized.list-style-type -> listStyleTypebackground-image -> backgroundImageThe only property that you'll have trouble with in Javascript is float. Some browsers use cssFloat, others use styleFloat. I'm not sure which of the two was for Internet Explorer now. This is probably because float in programming refers to a floating point number and they don't want to cause confusion.

Edited by Ingolme
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...