Jump to content

Setattribute Preferred But What About Style Elements?


nachumk

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...