Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74020

Use Javascript if/else statements to change HTML code

$
0
0

I've already got this code:

<h1 align="center" id="message" class="expandUp"></h1>
                <script type="text/javascript">
                        var d = new Date();
                        var n = d.getDate();

                        if ( n == 1) {
                                message = "<img src='image1.png'></img>";
                        } else if ( n == 2) {
                                message = "<img src='image2.png'></img>";
                        } else if ( n == 3) {
                                message = "<img src='image3.png'></img>";
                        } else {
                            message = "<img src='default.png'></img>";
                        }

                        document.getElementById("message").innerHTML = message;
                </script>

It displays a different image under h1 if the if/else statements are met. I wanna know how I can change in-page html code instead of displaying an image, such as disabling a specific button or hiding a div. I wonder if I should use some other function between the the if/else statements instead of message = "<img src></img>";

Thanks in advance.


Viewing all articles
Browse latest Browse all 74020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>