Click here to Skip to main content
12,446,146 members (44,379 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Javascript
<!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 4-Oct-12 11:15am
udoyen576
Updated 4-Oct-12 11:18am
v2
Comments
   
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100