JavaScript is known to host some quirky behavior. Most of the time however, all it takes is getting familiar with it to understand what is really happening and how to work with it.
New and experienced users sometimes run…
Read article
With the advent of jQuery, coding in JavaScript became accessible to almost everybody. But with it came some very fundamental errors that could have been avoided if the person read the very basic of java script.
Users de…
Read article
Sometimes you want to get the width of an element, and the obvious way of getting it does not work.
element.style.width; // (empty string)
Yeah, I know it should be this easy but it is not. Instead we have to get the co…
Read article
I have worked with PHP extensively and it is very convenient to have all the URL parameters automatically assigned to the global array $_GET. Here is an example:
http://www.example.org/?foo=bar
$_GET['foo']; // bar
I wis…
Read article
You can make use of recursion easily in JavaScript. Let's try it with factorials:
function factorial(num){
if (num < 0) {
return -1;
} else if (num == 0) {
return 1;
}
return (num …
Read article
There are times you want to make a very quick web request and don't care about the response looks like. It is possible to make requests using Ajax, but we still get a response.
One trick you will see many people are usin…
Read article
There are many ways to track when a user clicks on a link. It seems simple enough but there is something that people always forget and their code doesn't run. Let me show you an example.
Click me
// JS
var link = docume…
Read article
It is simple to load images to the page using JavaScript. We can create it using two methods then append it to the DOM.
var img1 = document.createElement("img");
var img2 = new Image();
img1.src = "path/to/image1.jpg";
…
Read article