I understand the importance of learning jQuery, but I prefer to delve into raw JavaScript first. Can someone assist me without the use of jQuery for better understanding? Thank you!
Hello, I'm fairly new to JavaScript and have recently started my learning journey. The navigation code that I've included below is functional, so I'll leave it untouched.
However, I'm facing an issue with the second block of code. I've been exploring event listeners and other concepts through online videos, and while everything seems to make sense to me, I'm still unable to achieve the desired outcome!
My goal is to display the div with the id "cs" when CSS is clicked, and similarly for HTML and JavaScript.
Unfortunately, I lack sufficient knowledge in JavaScript to troubleshoot this on my own. I'm completely stuck and unsure how to resolve the problem!
If anyone could provide assistance, I would greatly appreciate it. My frustration is mounting, and I can't seem to figure it out before bedtime!
Below is the code snippet, along with a link to the JS Fiddle: https://jsfiddle.net/pmj26o9p/2/
var htm = document.getElementById('htm');
var css = document.getElementById('css');
var js = document.getElementById('js');
htm.addEventListener("click", contentShow);
css.addEventListener("click", contentShow);
js.addEventListener("click", contentShow);
function contentShow() {
var whichOne = this.attributes["data-id"].value;
var switcheroo = document.getElementById(whichOne);
switcheroo.onclick = function() {
if (switcheroo.style.display === "none") {
switcheroo.style.display = "";
} else {
switcheroo.style.display = "none";
}
}
EDIT: Upon reviewing the code again, I realize that even if it functions properly, it won't achieve what I intended. This will allow me to show/hide the clicked element, correct?
Instead, I aim to display the selected item while hiding/applying display:none to all others that remain unclicked.