Javascript table is not rendering using CSS

212 Views Asked by At

I created a table using JavaScript, but it doesn't render using my css. so how can I make it work? actually i need more help, my idea is to create a screen that has one button and once you click on it a menu which is a table of one column starting at the top of the screen and end at the end of the screen should be showing. the table would be scrollable and each row has text (url text) with no url line under the text, so when you click on it the page open in all of the screen behind the table and the button. the button should be always showing (but it disappears when i click on it). the main.js file is

     function makeTableHTML() {
    var x = document.createElement("TABLE");
    x.setAttribute("id", "myTable");

    var myArray = [ [ "Name, http://www.google.com" ],
            [ "Name, http://www.google.com" ] ];
    var result = '<table width = "300">';
    for (var i = 0; i < myArray.length; i++) {
        result += "<tr><td>";
        if (i < 10) {
            result += "0" + i + "  ";
        } else {
            result += i + "  ";
        }

        result += '<a href="' + myArray[i][0] + '">';

        result += myArray[i][1] + "</a>";

        result += "<td></tr>";

    }
    result += "</table>";
    document.write(result);
    document.getElementById("channelsmenu").classList.toggle(result);
}

function hideTableHTML() {
    var x = document.getElementById('channelsmenu');
    x.style.display = 'none';
}

and my html is

    <!DOCTYPE html>
<html>
<head>

<title>5Star-IPTV</title>

<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/main.js"></script>
</head>

<body>

    <div>
        <table>
            <tr>
                <td>
                    <div id="channelsmenu" class="dropdown-content"></div>

                </td>
                <td class="buttons-col"><input type="image"
                    src="channels-menu.png" class="buttons" alt="channels menue"
                    onMouseOver="this.src='channels-menu-1.png'"
                    onMouseOut="this.src='channels-menu.png'" onclick="makeTableHTML()" /></td>
                <td class="buttons-col"><input type="image"
                    src="return-button.png" alt="return button" class="buttons"
                    onMouseOver="this.src='return-button-1.png'"
                    onMouseOut="this.src='return-button.png'" onclick="hideTableHTML()" /></td>
            </tr>
        </table>
    </div>
</body>
</html>

and this is the css

table {
    width: 100%;
    border: 1px solid black;
    background-color: #808080;
}

tr {
    width: 100%;
    align: right;
}

th, td {
    text-align: right;
}       background-color: #808080;
}

.buttons-col {
    text-align: center;
    width: 90px;
    padding-top: 5px;
}
1

There are 1 best solutions below

5
On

in HTML you open "th" and close it as "tr". Secondly, please learn to write/format your code properly - it'll be easier to read your code and to help you.

Besides, use the < script > tag at the end of the HTML or run your JS in the function on event DOMContentLoaded