In node.js you can use console.log or sys.puts to print out to the screen. What is the preferred method and what is the difference between these? Answer sys.puts simply prints the given string in the logs. But if you want to print a more complex object (Array, JSON, JSObject) you have to use console.log because you want to “look inside”
Tag: javascript
Is it possible to connect to SSH using JavaScript?
I know there is an implementation of VNC using WebSockets (http://novnc.com) but that still requires a server. I am looking to create a simple client-side JavaScript only (no Flash) connection to a port running SSH. I am guessing WebSockets is the only way to go since it does TCP. Any example code? Any other way? Answer Sorry, given your constraints
Defer JavaScript execution till the content has been added to Document
I am trying to load some content into a page using Ajax. The html that is loaded contains some JavaScript code. Even though the code is wrapped within $(document).ready, it gets executed before the content is inserted into the document, because the parent document’s Dom is ready by the time the content is loaded. How can I defer the execution
The best way to bind event on a cell element
I’ve a web page fulfilled by a JS script that creates a lot of HTML tables. Number of <table> created can vary between 1 and 1000 with 100 cells in each of it. My question is : how to bind efficiently the click on theses tables? Should I bind the click on each cell of the <table> or directly to
Iterating over result of getElementsByClassName using Array.forEach
I want to iterate over some DOM elements, I’m doing this: but I get an error: document.getElementsByClassName(“myclass”).forEach is not a function I am using Firefox 3 so I know that both getElementsByClassName and Array.forEach are present. This works fine: Is the result of getElementsByClassName an Array? If not, what is it? Answer No, it’s not an array. As specified in
Does an external .js file require tags?
Does an external .js file require internal and containing tags to work? Answer No, they’re not needed, in fact you’ll get a syntax error if you include them. Your .js files should contain only JavaScript, no HTML tags around it, like would have inside a page.
Fire a function on a element
I need to add a color picker to some input elements. I’m using: This works perfectly. The problem is that the page has a AJAX form, which – when submitted – will overwrite the previous form with a new one (new input fields etc). After that the colorPicker stops working. So how can I fire that function to the newly
Image onclick event for calling function is not working for Firefox and Chrome
I have a div section in which I have an image whose onclick event should execute a function called in it, but it is not executable in Firefox or Chrome with my code, infact the image is not clickable at all . Could some one help me in get the thing done? Below is the code I am working with:
Javascript regular expression: remove first and last slash
I have these strings in javascript: and I would like to remove the first and last slash if it’s exists. I tried ^/(.+)/?$ but it doesn’t work. Reading some post in stackoverflow I found that php has trim function and I could use his javascript translation (http://phpjs.org/functions/trim:566) but I would prefer a “simple” regular expression. Answer “Replace all (/…/g) leading
Why does a return in `finally` override `try`?
How does a return statement inside a try/catch block work? I’m expecting the output of this function to be true, but instead it is false! Answer Finally always executes. That’s what it’s for, which means its return value gets used in your case. You’ll want to change your code so it’s more like this: Generally speaking you never want to