125 views

Use Of Style Attribute in javascript (use of css)

style attributes are easily applicable to javascript code.

object.style.styleattribute

There is one basic rule you have to follow that is: if there is two name in style attribute like margin-left etc. write the first name(name before hyphen) as it is while the first letter of second name should be capital so:

margin-left = marginLeft

margin-top = marginTop

backgorund-color = backgroundColor

but single word’s attribute shoud be write as it is.

color = color

Example:

  1. <table border="0">
  2. <tbody>
  3. <tr>
  4. <td id="style_class" style="width: 80px; height: 50px;"></td>
  5. </tr>
  6. </tbody></table>
  7. <strong>Color:</strong>
  8.  
  9. <input onclick="getElementById(’style_class’).style.background=’red’" name="botton" type="button" value="Red" /> <input onclick="getElementById(’style_class’).style.background=’green’" name="botton" type="button" value="Green" /> <input onclick="getElementById(’style_class’).style.background=’blue’" name="botton" type="button" value="Blue" /

Color:

 
 

Post a Comment

You must be logged in to post a comment.