![]() Initially, first CSS class is applied as the demo page loaded. You see, three CSS classes are created for HTML table in the section of tag. So the table looks or class of CSS will be changed inside the switch case statement by using the JS code. In switch JavaScript statement, the theme value is checked in multiple cases and the one that turns out as true, it will execute the following statement:ĭocument.getElementById(“switchtable”).className A dropdown is given to select the theme for the table.Īs you select a table theme and press the button, a JS function will execute that runs the switch statement. In this demo, I have created an HTML table with CSS classes for and. JavaScript switch statement with HTML table Because, if I had placed this code in tag, then text in the div would not have displayed, since div is created in the tag while code executes prior to code. You may use this for displaying some important events, quotes or other messages related to that month.Īlso, note that I placed section just before the tag this time. The reason was to check the month and display a message accordingly. No function is used this time instead, the script is executed as the web page is loaded. The corresponding current month message will be displayed in a div. The current month value (0-11) will be assigned to a variable that will be used as an expression in the switch statement.Īfter that, twelve case JavaScript statements are used one for each month. ![]() In this example, I will get the current month by using the date object. ![]() An example with current month in Switch case
0 Comments
Leave a Reply. |