1

I am currently making some accessibility options which make the font size increase or decrease on a page. Following EndangeredMassa's for calling JS from a link it appears not to work!

My current code (which is dummy code with the right IDs which will be used in my actual site), does not even run a Javascript alert, and since I'm not one for Javascript, if anyone could let me know what I'm doing wrong.

HTML

<p id="html">Nice to meet you!</p>
<a id="incFontS" href="#">Increase Text</a>

JavaScript

var incFont = document.getElementById("incFontS");
incFont.onClick = function () {
    window.alert("it ran!");
}

As you can see from my jsfiddle, the code does not work at all, and I haven't even gotten to the part where I start changin the font sizes (geh!).

Any help is greatly appreciated!

Community
  • 1
  • 1
Adam
  • 146
  • 1
  • 15

4 Answers4

2

Case matters in JavaScript. The correct property name is onclick (with a lowercase 'c'). Try this:

var incFont = document.getElementById("incFontS");
incFont.onclick = function () {
    window.alert("it ran!");
}

Demonstration

Also, be sure to read addEventListener vs onclick for a discussion about different techniques for binding event listeners.

Community
  • 1
  • 1
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
1

DEMO

var incFont = document.querySelector("#incFontS");
incFont.addEventListener('click', function () {
    window.alert("it ran!");
    return false;
});
Gildas.Tambo
  • 22,173
  • 7
  • 50
  • 78
1

The function name is onclick not onClick

i.e.

var incFont = document.getElementById("incFontS");
incFont.onclick = function () {
    window.alert("it ran!");
}

works for me.

Alex Pakka
  • 9,466
  • 3
  • 45
  • 69
0

Try this way to do increase your font size

HTML CODE

<p id="html">Nice to meet you!</p>
<a id="incFontS" href="#" onclick="myFunction()">Increase Text</a>

Java Script Code

<script>
function myFunction() {
    document.getElementById("html").style.fontSize="xx-large";
}
</script>
it's me
  • 188
  • 1
  • 1
  • 10