JavaScript dom editors

so I m struggling with simple coding in js dom , because I m using Notepad++ and it doesnt underlines anything as warning or error and I cant orient what to correct . I m using alerts to know where my code stops working and it is super irritating . Can someone suggest me an editor for javascript DOM ? And I cant understand why it is not running simple pieces of code like this one :

<html>
<body>

xDOC=new ActiveXObject("Microsoft.XMLDOM");

xDOC.async="false";
xDOC.load("pti_project.xml");
x=xDOC.getElementsByTagName("employee");
alert("1");
for(c=0;c
</body>
</html>

It passes first alert , means everything loaded , but the second alert , never goes in the loop . Why , I mean it is simple loop and acumulating in a variable , sorry I m new .


Source: stackoverflow-javascript

Misunderstanding lifecycle hooks VueJS

I’m starting a tuto on the framework Vue.JS.

I m using the life cycle created of the Vue. I thought that this function was called once the vue is created. But in this example,
A behavior that I do not understand.

<template>
  
</template> export default { name: 'game', created: function () { console.log('On Vue created') document.onkeydown = this.start }, methods: { clickOnRound: function (event) { console.log('Click') }, bonus: function (event) { console.log('Click + alt') console.log(event) }, start: function (event) { console.log('Start called') console.log(event) } } }

When I type a letter on the keyboard, the function start is called, without calling the function of created.

Here the console output:

  • On Vue created
  • Start called
  • Start called
  • Start called
  • Start called

I can t understand how the start function is called without calling each time the created function , because the start function is inside the created function.

 created: function () {
      console.log('On Vue created')
      document.onkeydown = this.start
    },


Source: stackoverflow-javascript

Merging redundant tags with JavaScript. (Jquery)

I’m creating a middlewhere between systems, and get outdated html like the following:

<font size="4">Step 1: This is a </font><strong>step</strong><font size="4">.</font>

<ol style="margin-top:0pt;margin-bottom:0pt;">
    <li>This is my first substep.</li>
...

ol starts the steps, but the first line defines the name. I need to convert line 1 to:

<font size=4>Step 1: This is a step.</font>. 

In some cases, there may be a span after the last font tag, but there will never be a font tag that isn’t in the step title. It is crucial that it follows the

<font size=4> Step 1: ... </font> or <font size=4> Pre-Step 1: ... </font> 

format. I am using jQuery.


Source: stackoverflow-javascript

prevent scroll resetting after dom mainpulation

i’m using an external plug-in that manipulate the dom which in turn cause vertical scroll reseting on clicking

i know there is similar questions but non of them worked for me

i’ve tried handling it on ‘change’ but it never fired the event

$(document).on('change', '.element', myfunc());

the function absolutely have to remove and place element, there is no way to hide or change value, any suggestions are highly appreciated

i did try to check hash anchor solution for tips and pointers but failed miserably, same thing with focus

is there anyway to handle that resetting so i would prevent it ?


Source: stackoverflow-javascript

Automatic vs Manual escaping HTML

I faced that automatic (script-way) and manual escaping of HTML leads to different results – the manual way gives a better, more accurate results. I want to understand how negligence of script-way may be fixed.

Here are examples.

Div

The

tag is the least problematic of all. In both auto and manual methods the result will be the same.

Auto:


foo

div
bar </pre> var pre = document.querySelector("#outer"); pre.innerHTML = pre.innerHTML .replace(//g, '>'); </body>

Manual:

<body>
<pre id="outer" style="background-color: #eee;">
foo

&lt;div>
div
&lt;/div>

bar
</pre>
</body>

Result:

enter image description here

Body

The <body> tag properly rendered only in case if I do replacements manually.

I understand why it occurs*, but I don't understand how I may fix it.

* That's because document can have only one <body> tag, and document already have one of it, initially (obviously, top line of snippet). And so, the next, "fake body" (i.e. body inside <pre> tags ) is merged with the first, before it become escaped.

Auto:

<body>
<pre id="outer" style="background-color: #eee;">
foo

<body>
body
</body>

bar
</pre>


var pre = document.querySelector("#outer");
pre.innerHTML = pre.innerHTML
    .replace(//g, '>');

</body>

Manual:

<body>
<pre id="outer" style="background-color: #eee;">
foo

&lt;body>
body
&lt;/body>

bar
</pre>
</body>

enter image description here

Pre

Nested <pre> tag also a bit problematic. See the indentation. In automatic way, text inside <pre> tag moved one line upper.

Auto:

<body>
<pre id="outer" style="background-color: #eee;">
foo

<pre>
pre
</pre>

bar
</pre>


var pre = document.querySelector("#outer");
pre.innerHTML = pre.innerHTML
    .replace(//g, '>');

</body>

Manual:

<pre id="outer" style="background-color: #eee;">
foo

&lt;pre>
pre
&lt;/pre>

bar
</pre>

enter image description here


Source: stackoverflow-javascript

Available modules in node script

why do I get different results when trying to find out more about the http module in node.js in the following to ways?

  1. If I enter the node REPL and then print the content of the http module, i.e. if I run

    me@mymachine:~> node
    > console.log(http)
    

    I get all the details of the http object:

    { IncomingMessage: { [Function: IncomingMessage] super_: {
    ...
    
  2. If I write a script file called, say, script.js containing the following single line

    console.log(http);
    

    and execute it by running

    node script.js
    

    I get

    ReferenceError: http is not defined
    

I would have expected both cases to behave in the same way – either the http module is preloaded or not. Why is there a difference? What am I getting wrong here?

I thought I could ‘fix’ this by preloading module http by running (in version 2)

node -r http script.js

Shouldn’t this preload module http and thus avoid the reference error?

Looking forward to your input!