23 Dec, 2024

How to display image with javascript?

You could make use of the Javascript DOM API. In particular, look at the createElement() method. You could create a re-usable function that will create an image like so… function show_image(src, width, height, alt) { var img = document.createElement(“img”); img.src = src; img.width = width; img.height = height; img.alt = alt; // This next line […]

Share your Love
1 min read

Hide Div using Javascript

To hide a div element using JavaScript, you can set its style. Display property to “none“.  Here’s an example: <!DOCTYPE html> <html> <head> <title>Hide a div with JavaScript</title> <script> function hideDiv() { var divElement = document.getElementById(“myDiv”); divElement.style.display = “none”; } </script> </head><body> <div id=”myDiv”> <p>This is the content of my div element.</p> </div> <button onclick=”hideDiv()”>Hide […]

Share your Love
1 min read