The Entrepreneur Forum | Financial Freedom | Starting a Business | Motivation | Money | Success

Welcome to the only entrepreneur forum dedicated to building life-changing wealth.

Build a Fastlane business. Earn real financial freedom. Join free.

Join over 80,000 entrepreneurs who have rejected the paradigm of mediocrity and said "NO!" to underpaid jobs, ascetic frugality, and suffocating savings rituals— learn how to build a Fastlane business that pays both freedom and lifestyle affluence.

Free registration at the forum removes this block.

JavaScript is a PAIN in the

Black_Dragon43

Legendary Contributor
FASTLANE INSIDER
EPIC CONTRIBUTOR
Read Fastlane!
Speedway Pass
User Power
Value/Post Ratio
337%
Apr 28, 2017
2,071
6,969
‍☠️ Eastern Europe
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
Bro! Put a F*cking dot before "menu-icon". Should be var menuIcon = document.querySelector(".menu-icon"); if you're selecting a class.

Also specify in brackets what class you want to add/remove in .toggle("YOUR CLASS GOES HERE")
 

Toyotomi

Contributor
FASTLANE INSIDER
Read Rat-Race Escape!
Read Fastlane!
Read Unscripted!
Speedway Pass
User Power
Value/Post Ratio
109%
Jun 27, 2021
32
35
29
United Kingdom
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
@Black_Dragon43 and @Martin Z are both right on the cash, beyond that, are you deploying this anywhere? Or are you doing all of this locally?

Can we see how you are adding the script? Do please include your index.html as well.

Also as a tip don't expect things to just exist check if sidebar exist (useful in the future when stuff changes moves around), also prefer to pass sidebar as an argument instead of having it as a global variable at the top of your script.

Here is a code pen I made for just you friend. Hopefully it helps.
 
Dislike ads? Remove them and support the forum: Subscribe to Fastlane Insiders.
Last edited:

David Borodin

Contributor
Read Fastlane!
User Power
Value/Post Ratio
75%
Oct 1, 2021
44
33
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
 
Dislike ads? Remove them and support the forum: Subscribe to Fastlane Insiders.

K1 Lambo

Silver Contributor
Read Rat-Race Escape!
Read Fastlane!
Read Unscripted!
Speedway Pass
User Power
Value/Post Ratio
138%
Oct 11, 2021
564
778
Oslo
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
You forgot the . in your querySelector for menu-icon.
 

Post New Topic

Please SEARCH before posting.
Please select the BEST category.

Post new topic

Guest post submissions offered HERE.

Latest Posts

New Topics

Fastlane Insiders

View the forum AD FREE.
Private, unindexed content
Detailed process/execution threads
Ideas needing execution, more!

Join Fastlane Insiders.

Top