External Js File Not Working In React
Active 2 years ago.
External js file not working in react. External javascript is not working in react js. By doing this you are executing your js code before full html content has been attached. Any idea of why the function would work with the inline javascript but not with the imported javascript. Custom is the path to the file that holds your js code import toggleicon from custom.
Viewed 4k times 2. How is that even possible. Ask question asked 2 years ago. The part i commented out in the js file was the previous method i was trying to use.
Initially my js file was empty as i began testing the html structure. I m trying to use an external javascript file in order to write hello world into a html page. The js file was there it was in the same directory but the content of the file was memory cached in the browser. Later when i added code to the js file the browser window which had been open did not re read the js file even after refreshing the browser.
Fyi i am using visual studio 2008 professional and i am working with an asp net web application. I have multiple external js file like in your case like jquery bootstrap owl carousel. Well organized and easy to understand web building tutorials with lots of examples of how to use html css javascript sql php python bootstrap java and xml. I have some.
If your html file is in what we will call your root folder and the js file is indeed in the scripts folder relative to where the html file is located but it isn t working the. All the css are working fine but the javascript libraries are not working on the page. I would rather have my code defined in an external file so getting it to work that way would be ideal. However for some reason it does not work i tried the same function and commands inline and it worked but not when it s using an external javascript file.
As a result when your js code executes it does not recognize any html element because there isn t any. Everyone s answers kept saying it was either because the script tag wasn t being used in the html file or the code wa. I created a react app using create react app and i copied all the external javascript libraries and css files in index html of the public folder of my react app and copied all the html of index html of my theme in app js which i downloaded. I just came across this issue just now and couldn t find any good answers googling or even on quora.
Most likely the problem is that you are including your js file in a head tag or somewhere above your main content.