Reputation: 35
I have made a hyperlink, styled to look like a button, and set it do onClick="function()"
, but when I click it it won't execute. I have my JS in a separate file than the HTML file if that is of any use.
How I linked it
<script src="script.js"></script>
The Hyperlink
<ul id='nav'>
<li>
<a onClick="playerNum()">Play</a>
</li>
<li>
<span style='float: right;'>
<a onClick="rules()">Rules</a></span>
</li>
</ul>
My JavaScript
var playerNum = function () {
document.getElementById('log').innerHTML =
"<h2 style='font-family: calibri'> Choose single or multiplayer </h2>" +
"<br >" +
"<ul id='nav'>" +
" <li> <a onClick='singlePlay()'> Singleplayer </a> </li>" +
" <li> <a onClick='multiPlay()'> Multiplayer </a> </li>" +
"</ul> "
};
Upvotes: 0
Views: 211
Reputation: 8475
It works for me. Do you have an element with id="log"
?
fiddle: http://jsfiddle.net/o7b83omw/1/
HTML:
<ul id='nav'>
<li>
<a onclick="playerNum()">Play</a>
</li>
<li>
<span style='float: right;'>
<a onclick="rules()">Rules</a></span>
</li>
</ul>
<div id='log'></div>
javascript:
var playerNum = function () {
document.getElementById('log').innerHTML =
"<h2 style='font-family: calibri'> Choose single or multiplayer </h2>" +
"<br >" +
"<ul id='nav'>" +
" <li> <a onClick='singlePlay()'> Singleplayer </a> </li>" +
" <li> <a onClick='multiPlay()'> Multiplayer </a> </li>" +
"</ul> ";
};
Upvotes: 2