javascript - How to get BGCOLOR of a TD? -


how value of bgcolor? (my alert wrong).

<table id="mytable1" onclick="setcolor()" width="25" border-color:black border="1" cellspacing="1" cellpading="0" align="left">     <tr>           <td id='colorid' bgcolor=yellow>&nbsp;</td>     </tr> </table>  <script type="text/javascript"> alert(document.getelementbyid("colorid").getattribute('bgcolor')); </script> 

javascript case-sensitive. getattribute() should written lowercase g (like getelementbyid , others). called camel-case (or camelcase , name says is), javascript functions follow naming convention.

document.getelementbyid("colorid").getattribute('bgcolor') 

also can't write css directly html element, have use style attribute:

style="border-color: black;" 

one more thing, if let me. try consistent in markup style. in html4/5 can use either ', " or nothing around attribute values (like id="colorid", id='colorid' or id=colorid), should stick 1 of these in same html page (not cannot mix them, staying consistent considered better practice).


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -