Simple onmouseover for javascript call not working

In a simple html page, I have:

<SCRIPT>
function Clicker(number){
if (number == 1) 
document.write ('<style type="text/css">body {background-color: #cccccc;}</style>');
}
</SCRIPT>

and in the html package:

<a onmouseclick="Clicker(1)" href="#">clic</a>

But when I click on the link, nothing happens. Where am I mistaken?

+3
source share
3 answers

Writing a style block will probably not affect the background color change. To do this, you need to manipulate the Document object:

<script type="text/javascript">
function Clicker(number){
if (number == 1) 
    document.body.style.background='#cccccc';
}
</script>

Your click event should also be onclick:

<a onclick="Clicker(1)" href="#">clic</a>
+2
source

Just change onmouseclick to onclick .

+1
source

"onclick", .

<a onclick="Clicker(1)" href="#">clic</a>
0

Source: https://habr.com/ru/post/1736845/


All Articles