Click here to Skip to main content
Rate this: bad
good
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 12:15pm
udoyen511
Edited 4-Oct-12 12:18pm
v2
Comments
Sergey Alexandrovich Kryukov at 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

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

  Print Answers RSS
0 Zoltán Zörgő 300
1 Peter Leow 150
2 BillWoodruff 120
3 CHill60 100
4 CPallini 80
0 Sergey Alexandrovich Kryukov 9,423
1 OriginalGriff 6,891
2 Peter Leow 4,692
3 Zoltán Zörgő 4,344
4 CHill60 2,932


Advertise | Privacy | Mobile
Web03 | 2.8.150129.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2015
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