Click here to Skip to main content
15,895,797 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta  charset="utf-8"/>
    <title>Html Page</title>
    <script src="Content/scripts/jquery-1.8.0.min.js"></script>
    <script src="Content/scripts/jquery-ui-1.8.24.custom.min.js"></script>
    <script type="text/javascript">
'I need help. My webpage won't respond to my Javascript code as shown below and was trying to change the table attributes using Javascript but the changes do not show when I load the page in my browser:
        function changeStyle(myTable) {
            var change = document.getElementById("myTable");

            if (change == true) {
                change.style.borderWidth = "4px";
                change.style.backgroundColor = "blue";
            };changeStyle()
        }
        
    </script>
    <style type="text/css">
        .auto-style1 {
            width: 294px;
        }
    </style>
</head>
<body>
    <div>
        <table id="myTable" style="width: 300px; height: 500px; border: solid 1px black; background-color: Red;">
            <tr>
                <td class="auto-style1">Hello </td>

            </tr>

        </table>
    </div>
</body>
</html>
Posted
Updated 4-Oct-12 11:18am
v2
Comments
Sergey Alexandrovich Kryukov 4-Oct-12 18:31pm    
What exactly did you try to achieve, and what do you see, in response to what events? Did you try to run anything under debugger?
--SA

1 solution

In this code, I cannot see any event handler at all. Besides, you include jQuery library, but never use it. If this is all you have, absolutely no wonder that nothing happens.

If you want a typical jQuery approach, which I would strongly recommend, you can handle only document.ready and add other handlers in the handler of this event, so you never need adding any handlers in HTML. In this case, this script should come in <body>, not in <head> element:
http://docs.jquery.com/Tutorials:How_jQuery_Works[^].

Also, do you know how to use the debugger?

—SA
 
Share this answer
 
v3
Comments
udoyen 4-Oct-12 18:42pm    
Hi SA,
Are u saying I should have put an event handler in the table?
George
Nigeria
Sergey Alexandrovich Kryukov 4-Oct-12 19:10pm    
No! Please see how jQuery works, the link.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900