• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Apr 27, 2022 Apr 27, 2022

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>

Views

406

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

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)?  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2022 Apr 28, 2022

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'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

twice ???

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

LATEST
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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2022 Apr 28, 2022

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>

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines