external-js

External JS with onLoad Event

岁酱吖の 提交于 2019-12-22 08:37:17
问题 I have an external js file which has a function that is meant to run AFTER the document body has loaded. This is what I have so far but it's not working as it should. Some help please. External JS File window.document.body.addEventListener('load', numOfSelects()); function numOfSelects() { var selects = document.getElementsByTagName('select'); alert(selects.length); } The HTML file that calls this script does have a few select fields. The alert works but it shows 0. And after the alert shows

Close HTML Script Tag [duplicate]

廉价感情. 提交于 2019-12-21 06:48:26
问题 This question already has answers here : Why don't self-closing script elements work? (12 answers) Closed 6 years ago . I just curious why my JavaScript can't run (tested in Firefox and IE) if I write the <script> tag like this: <script type="text/javascript" src="script.js"/> It will work if I change that line to: <script type="text/javascript" src="script.js"></script> So my question is: why I can't close the script tag in the start tag since I don't have any content inside it. My

ESLint showing errors in Brackets

ぃ、小莉子 提交于 2019-12-04 07:35:33
问题 My javascript code is working perfectly except ESLint is showing that I have errors, such as: "ERROR: 'myFunction' is defined but never used. [no-unused-vars]" and "ERROR: 'document' is not defined. [no-undef]" This is only a problem because I am using an external js file. What can I put into "brackets.json" or "defaultPreferences.json" to stop these ESLint error markers/notifications from appearing? Any help is much appreciated. 回答1: I had the same problem: create a package.json file a the

Close HTML Script Tag [duplicate]

江枫思渺然 提交于 2019-12-03 22:12:07
This question already has answers here : Closed 6 years ago . Why don't self-closing script elements work? (11 answers) I just curious why my JavaScript can't run (tested in Firefox and IE) if I write the <script> tag like this: <script type="text/javascript" src="script.js"/> It will work if I change that line to: <script type="text/javascript" src="script.js"></script> So my question is: why I can't close the script tag in the start tag since I don't have any content inside it. My JavaScript code is simple, just: alert("test"); Notes: I check firefox error console and no error. The concept

JavaScript not working on external file

心不动则不痛 提交于 2019-12-01 04:03:35
问题 When I use this code inside my HTML document it's working: $('a.tocenter[href*=#]').click( function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']'); if ($target.length) { var targetOffset = $target.offset().top; $('html,body').animate({ scrollTop: targetOffset - ( $(window).height() - $target.outerHeight(true) ) / 2 },