Skip to main content
Participant
April 28, 2022
Question

Why is it, when i click on my text with the onclick function in javascript, not working???

  • April 28, 2022
  • 2 replies
  • 689 views

so basically, i tried to do a sort of thing where when you click on some text some more text would appear under it, so i tried this and it didn't work! what went wrong?
(Javasciprt file)

/* global $, document*/
// JavaScript Document and stuff ya know
//homepage
function angy() {
document.getElementById('me').src='Angy.png'
ang.textContent = "Ahmad A. oh no now he angy now"
}

me.onclick = angy;
//page 1
//page 2
// page 3
function whe() {
whydo.classList.remove('hidden');
document.getElementById('whydoe');
whydoe.classList.add('clicked');
}

whydoe.onClick = whe;
// page 4
// page 5
// page 6

(Main html page)

p class="" >
<span class="titilles">Web browsing?</span> <br><br>
Well its sometimes referred to as surfing the web but yeah! <br><br>
<span id="whydoe" class="clickable">No, I meant what is it?</span><br><br>
<span class="hidden" id="whydo">Oh, well it refers to the action of</span>
</p><br>
<p>
<span class="titilles">HTML? What does that stand for?</span> <br><br>
Well, HTML is the main programming language (although it may or may not be an actual programming langueage) used to make websites on the internet.
</p>
<script type="text/javascript" src="othermain.js"></script>

    This topic has been closed for replies.

    2 replies

    Legend
    April 28, 2022

    Its probably not working as you can only have one id per page with the same name. You have used the id 'why do' twice in the code, which is going to confuse the script.

     

    Oooops ignore the above on a second look one of the whydos has an 'e'

    B i r n o u
    Legend
    April 28, 2022

    twice ???

    Legend
    April 28, 2022
    quote

    twice ???


    By @B i r n o u

     

    I thought it was twice until I studied the id names again:

     

    whydo

    whydoe

     

    Probably why one should use something more sensible and easily identifiable, makes life easier!

    Community Expert
    April 28, 2022

    I'm not seeing any syntax that is bad in your code. When you run the code in your browser, are you seeing any errors in the console (right click in your browser --> inspect --> console)?