Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Display image preview before upload using jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 151
    Comment on it
    <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        </head>
    
        <body>
            <img id="thumbnail" src="test.png" alt="Image"/>
            <div style="clear: both;"></div>
            <input type="file" name="file" id="file"/>
            <div style="clear: both;"></div>
            <button id="btn">Click</button>
    
            <script type="text/javascript">
                $(document).ready(function() {
                    $(document).on('click', '#btn', function() {
                        var reader = new FileReader();
                        reader.onload = function (e) {
    
                            $('#thumbnail').attr('src', e.target.result);
                            }
                        reader.readAsDataURL(file.files[0]);
                        });
                    });
            </script>
    
        </body>
    </html>
    

 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: