Find us on Google+ Kill the code: Image Swaping in Javascript

Thursday, 1 March 2012

Image Swaping in Javascript

Preview : 


New Web Project




Code :




<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
    </head>
    <body>
    <script type="text/javascript">
    function swap() {
    var t = document.getElementById("i1").src;
    document.getElementById("i1").src = document.getElementById("i2").src;
    document.getElementById("i2").src = t;
    return;
    }
    </script>
        <img src="1.png" id="i1"/>
        <img src="2.png" id="i2"/>
        <input type="button" id="but" value="swap" onclick="return swap()"/>
        <a href="http://killthecode.blogspot.in">For more programs click here</a>
    </body>
</html>

4 comments: