VSCode - Weird syntax formatting for JavaScript files upon saving - javascript

I noticed something weird going on when hitting ctrl+s in VSCode.
I have some JavaScript here and each time I hit ctrl+s lines 7+8 will get indented. At first I thought it was because of some extension rules (using Beautify for example). So I disabled all my extensions but still the following happens:
Then I noticed that removing the tags fixes the auto-formatting issue.
But why is that, any ideas?
Thanks.

Then I noticed that removing the tags fixes the auto-formatting issue.
If this is a .js file, you shouldn't have HTML in it. The tags shouldn't be there.

Related

Why would renaming HTML file fix an element positioning bug in Chrome?

I am writing a simple run and jump game using only a few hundred lines of vanilla JS, HTML and CSS. So far nothing complicated whatsoever.
My game was running okay, then without warning broke - suddenly the player element was offset down and to the right. Couldn't see any reason in code for this, and realized that just renaming the html file fixes the bug.
Also, opening the html file in firefox works perfectly with no bug (using original "chrome-buggy" name).
Any clue what could be the reason for this?
I don't care so much about making it work - since it already works with a new html file name. I'm interested in understanding what could have caused the issue.
Thank you
Fixed. Cleared all browser data. Clearing "cached images and files" was not enough, and reload/hard reload was not enough.
I will check "disable cache" under "network" in dev tools from now on to avoid this problem.

How to add script tags to html

Here in the image you see the code is greyed out. Before I put in the <script> tag everything was not greyed out. Once I put in the tag is greys out the rest of the code. I might be missing a file needed to run the script tags?
I have been working with code for a while, but I am still a little stuck on how to get the code set up. I am wanting to use html/css and JavaScript to make a couple websites. I am not sure how to set everything up to make it work. I also am using github, and trying to figure out how to use github-pages.
A simple solution that works:
Just close the file being edited
Click "File->Reopen Last Item" to re-open it
This is an issue with Atom, it does not detect the tag when it auto completes, it works fine in VSCode, so it's not really a problem with your code, it's the IDE
enter image description here
As i recognize, the Atom text editor makes this error.
The best solution i tried:
IN ATOM TEXT EDITOR
Windows:
Ctrl + ,
MAC:
Cmd + ,
In settings:
1. Scroll to the bottom,
2. Uncheck "Use Tree Sitter Parsers",
3. Restart Atom IDE.
That works fine for me!
This is a known bug, but it seems no fix have been done yet, you can report your case here, I guess: HTML Syntax Colour Bug
But you may have solution in that StackOverflow subject, if so, it would be a duplicate: Atom Code Editor. Why is my code not in color?

JavaScript not working in Wordpress 3.4.2

I have never tried to use javascript in wordpress post before. Today, when I tried it does not work. I tried several scripts, and none work.
For example,<Script type="text/javascript"> alert("test");</script>
In the past, I have tried to use SweetCaptcha, and it did not work. I am thinking this may also have to do this issue.
Has anyone had a similar situation?
I have disabled ALL plugins just to ensure there are no conflicts with them.
I deactivated all plugins again, and activated them, and now it works. I did this several times before, but I guess that was the issue
Remove all spaces from your code. Try this:
<script type="text/javascript">alert("test");</script>
I have never tried to use javascript in wordpress post before.
Javascript should work if pasted into the HTML version of the Post/Page editor. It does not work if pasted into the visual editor. If pasted into the visual editor the string will be encoded and won't work. I just tested it.

My javascript file is displayed as a single line of text in the chrome debugger. Why?

I seem to run into this randomly. It usually displays the file normally, but sometimes it's all scrunched onto one line. I can't figure out what's causing it.
N.B.: In the current version of Chrome, this is actually done by clicking on the {} icon ("pretty print") on the lower left of the developer tools pane.
Ah, figured it out. The line endings on the problem file got set to Mac format somehow, while the rest of the files were Windows format. Not sure how the format swapped but it's easy to convert back (in Notepad++ just go Edit -> EOL Conversion).
You already answered your own question, but this is a good place to note that Chrome (as of v12, currently in dev channel) has a built-in pretty-print function that can make quick work of the typical one-line JavaScript files that all well-behaved websites generate. In Web Inspector's Scripts tab, select a file via the usual dropdown, and right click on the source code. Selecting "De-obsfucate Source" will format the file in a reasonable way, and even allow you to set breakpoints inside the newly reformated code. It's quite helpful.

Aptana Studio 2 - Code Assist for JS is not working

My problem is somewhat strange. I have started developing a web page with Aptana Studio build 2.0.5.1278522500. Everything went fine up to the moment when I wanted to start writing JavaScript in a separate .js file - there's no code assist for it. In the preferences it's enabled, and - that's the strange part - it works perfectly well in the .html files (when typing code in the script tag). The only thing that could remotely tell there's something wrong is the fact, that when I type, say, "document" and hit the '.' key, the cursor disappears for a split of a second.
Did anyone have the same problem? Is there any solution to that? I'd like code assist for JS very much, without it Aptana somewhat loses it's appeal.
As CodeMonkey mentioned we can do the same at Aptana Stuidio version 3. I mean follow this path: (Preferences->General->Editors->File Associations). Select js at top list but because at studio 3 we should select JavaScript Source Editor as default. It did not work change it to another option save and again bring it back to JavaScript Source Editor (It happened for me). Now you can use it.
I found an answer to my question, I'll post because maybe it'll help someone. To get the code assist working I just changed file the default editor for .js files from JavaScript editor to Aptana JS editor (Preferences->General->Editors->File Associations, then selected *.js in the top list and Aptana JS Editor in the bottom list, then clicked the "Default" button). Now it works like a charm.
I got a similar problem on Aptana 3 Studio. I cannot reproduce the problem now and there is no option for Aptana JS Editor in 3. I think the key to solve the problem is: used the template to generate a new file, don't try to just rename a blank normal file, if so, you need to closed the file and reopen it.
Associating .js files with Aptana did not resolve this problem.
I noticed that when I type jquery(this). , I get code assistance and there was no assistance when I types $(this). So I fixed this thing temporarily by placing this statement
$ = jQuery;
at the start of my .js file, thus declaring the $ as an equivalent to the jquery function.
While writing Javascript code in HTML editor, you don't need to do that becuase you have included the jQuery reference at the top which has the above setting ($ = jquery).

Categories

Resources