Use Of Style Attribute in javascript (use of css)

59 views

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:

 
 



« Display And Hide Div,Span Elements or HTML Elements or Tags (Use Of style.display) Javascript Change String to Integer »
Posted on Tuesday, April 21st, 2009 at 2:15 pm under Javascript, Tips and tricks | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?