Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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)?
Copy link to clipboard
Copied
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'
Copy link to clipboard
Copied
twice ???
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
I don't know whats wrong with the code you posted (probably 'onClick' should be 'onclick') but this works:
<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>
<script>
const whydoe = document.getElementById('whydoe');
function whe() {
whydo.classList.toggle('hidden');
whydoe.classList.add('clicked');
}
whydoe.onclick = whe;
</script>