NEWS: Total Picture Views: 147060 | Total Article Views: 155589 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. How to read a JSON and work with it | 3. PickUpThings with Becker Robot | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

OnClick, OnMouseOver and OnMouseOut Example Javascript

Description:

In this example I will be showing you how to use OnClick, OnMouseOver and OnMouseOut.

Code:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .row1{
            background-color: #00ffff;
        }

        h2{
            background-color: darkgreen;
            color: pink;
        }
    </style>
</head>
<body>
    <h1 onclick="clickH1()" id="h1">This is heading 1</h1>
    <h2 onclick="ClickH2()" id="h2">This is heading 2</h2>

    <h3>Table Demo</h3>
<table border="1">
    <tr>
        <td class="row1" id="1" onclick="onClickTable(1)">Row 1</td>
        <td class="row1" id="2" onclick="onClickTable(2)">Row 1</td>
        <td class="row1" id="3" onclick="onClickTable(3)">Row 1</td>
    </tr>
    <tr>
        <td id="4" onclick="onClickTable(4)">Row 2</td>
        <td id="5" onclick="onClickTable(5)">Row 2</td>
        <td id="6" onclick="onClickTable(6)">Row 2</td>
    </tr>
    <tr>
        <td id="7" onclick="onClickTable(7)">Row 3</td>
        <td id="8" onclick="onClickTable(8)">Row 3</td>
        <td id="9" onclick="onClickTable(9)">Row 3</td>
    </tr>
</table>

<strong>This is an image</strong>
<br><img src="//upload.wikimedia.org/wikipedia/commons/5/5a/Flower_11.jpg" onmouseover="resizeImage()" onmouseout="imageOut()" height="100px" width="100px" id="image">
<p id="p">This is a paragraph</p>
<a href="index.html">Click me</a>

<script type="text/javascript">
    function resizeImage(){
        var h = document.getElementById("image").height;
        var w = document.getElementById("image").width;

        document.getElementById("image").style.height = (h * 2) + "px";

        document.getElementById("image").style.width = (w *  2) + "px";
    }

    function imageOut(){
        document.getElementById("image").style.height = 100 + "px";

        document.getElementById("image").style.width = 100 + "px";
    }

    function clickH1(){
        document.getElementById("h1").style.backgroundColor = "#000077";
        document.getElementById("h1").style.color = "yellow";
    }

    function ClickH2(){
        document.getElementById("p").style.backgroundColor = "#000077";
        document.getElementById("p").style.color = "yellow";
    }

    function onClickTable(x){
        document.getElementById(x).style.display = "none";
    }
</script>
</body>
</html>
Attachments: None

Tags: OnClick OnMouseOver OnMouseOut

Total Views: 943

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 02/25/15


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.