javascript - JS: document.write (calling CSS) -
javascript - JS: document.write (calling CSS) -
i'm dealing calling classes document write. defined 2 classes in css. first "sahovnica" (chessboard) , sec "svetlo" (light) , "temno"(dark). both classes defined style table. , wanted built table with: document.write( document.write('<td class="' + svetlo + '"></td>'););
tried many different ways, code don't works. if comment document.write(), page show up.
<!doctype html> <html> <head> <title>Šahovska partija 2014</title> <meta charset="utf-8"> <style> h1 { color:blue; font-family:verdana; font-size:125%; } .sahovnica { border-spacing: 0; border-collapse: collapse; } .sahovnica th { padding: .5em; } .sahovnica td { border: 1px solid; width: 2em; height: 2em; } .sahovnica .svetlo { background: #eee; } .sahovnica .temno { background: #000; } </style> </head> <body> <table class="sahovnica"> <script> var vrstica = parseint(prompt("vnesite številko vrstice", "")); var stolpec = parseint(prompt("vnesite zaporedno številko stolpca", "")); stolpec = stolpec -1 var value = vrstica + stolpec value = value%2 if (value == 0) { document.write( document.write('<td class="' + svetlo + '"></td>');); } else { document.write( document.write('<td class="' + temno + '"></td>');); } </script> </table> </body> </html>
this working
<!doctype html> <html> <head> <title>Šahovska partija 2014</title> <meta charset="utf-8"> <style> h1 { color: blue; font-family: verdana; font-size: 125%; } .sahovnica { border-spacing: 0; border-collapse: collapse; } .sahovnica th { padding: .5em; } .sahovnica td { border: 1px solid; width: 2em; height: 2em; } .sahovnica .svetlo { background: #eee; } .sahovnica .temno { background: #000; } </style> </head> <body> <table class="sahovnica" id="my_table"> <script> var vrstica = parseint(prompt("vnesite številko vrstice", "")); var stolpec = parseint(prompt("vnesite zaporedno številko stolpca", "")); stolpec = stolpec - 1 var value = vrstica + stolpec value = value % 2; var classtype =value? 'temno':'svetlo'; document.getelementbyid("my_table").innerhtml += '<td class="' + classtype + '"></td>'; </script> </table> </body> </html>
javascript html css document.write
Comments
Post a Comment