Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How show image on click event using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 573
    Comment on it

    Hello Reader's If you want to show image on a click event. Then using javascript you can use this in real time. Let's see the example below:-

    <button onclick="add_google_logo();">Add Google Logo</button>
    

    Now the JS will go like this:-

    function add_google_logo() {
        var src = "http://google.com/images/logo.gif"; //here you have to set the link of image
        show_image("http://google.com/images/logo.gif", 276,110, "Google Logo"); // give the details of image
    }
    
    
    function show_image(src, width, height, alt) {
        var img = document.createElement("img");
        img.src = src;
        img.width = width;
        img.height = height;
        img.alt = alt;
        document.body.appendChild(img);
    }
    

    Now when user click the button a div will open and show the image.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: