JavaScript string newline character?

I’ve just tested a few browsers using this silly bit of JavaScript:  Run code snippetExpand snippet IE8 and Opera 9 on Windows use \r\n. All the other browsers I tested (Safari 4 and Firefox 3.5 on Windows, and Firefox 3.0 on Linux) use \n. They can all handle \n just fine when setting the value, though IE and Opera … Read more

Is there a difference between /\s/g and /\s+/g?

In the first regex, each space character is being replaced, character by character, with the empty string. In the second regex, each contiguous string of space characters is being replaced with the empty string because of the +. However, just like how 0 multiplied by anything else is 0, it seems as if both methods strip spaces in exactly the … Read more

How do I change the background color with JavaScript?

Modify the JavaScript property document.body.style.background. For example: Note: this does depend a bit on how your page is put together, for example if you’re using a DIV container with a different background colour you will need to modify the background colour of that instead of the document body.

jQuery equivalent of JavaScript’s addEventListener method

Not all browsers support event capturing (for example, Internet Explorer versions less than 9 don’t) but all do support event bubbling, which is why it is the phase used to bind handlers to events in all cross-browser abstractions, jQuery’s included. The nearest to what you are looking for in jQuery is using bind() (superseded by on() in jQuery 1.7+) … Read more

How to add jQuery code into HTML Page

1) Best practice is to make new javascript file like my.js. Make this file into your js folder in root directory -> js/my.js . 2) In my.js file add your code inside of $(document).ready(function(){}) scope. 3) add your new js file into your html

Can’t resolve module (not found) in React.js

The way we usually use import is based on relative path. . and .. are similar to how we use to navigate in terminal like cd .. to go out of directory and mv ~/file . to move a file to current directory. In your case, App.js is in src/ directory while header.js is in src/components. To import you would do import Header from ‘./components/header’. This roughly translate to in my current directory, find the components folder that … Read more

pretty-print JSON using JavaScript

Pretty-printing is implemented natively in JSON.stringify(). The third argument enables pretty printing and sets the spacing to use: If you need syntax highlighting, you might use some regex magic like so: See in action here: jsfiddle Or a full snippet provided below: Show code snippet

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)