Home Posts tagged "tutorial"
formats

JavaScript Closures – The Absolute Basics: Getters and Setters

The next step in mastering JavaScript closures is being able to “get” or “set” a private variable In Part I of this series: JavaScript Closures – The Absolute Basics, I discussed wrapping one function with another, which produces a closure. When that returned function is assigned to a variable, as long as that variable is

(More)…

formats

PHP’s array_push() and array_unshift() fucntions

in PHP.

If you need to add values to the beginning or end of an array, use the array_push() and array_unshift()  functions array_push() This function allows you to add one or more values to the end of an array. Syntax:   <?php $beatles = array(“John”, “Paul”); echo “The Duet is:”; print_r($beatles); array_push($beatles, “George”, “Ringo”); echo “The Quartet

(More)…

formats

JavaScript Closures – The Absolute Basics

Demystifying this topic is one of the most important steps towards truly understanding the JavaScript language It is a little difficult to get your head around JavaScript closures without a basic understanding of scope. I will not attempt to tackle that subject in any kind of detail here. But let’s at least consider this thought: JavaScript

(More)…

formats

Iterating Over a jQuery Collection with the .each() Method

in jQuery.

jQuery makes it super easy to get a reference to a collection of DOM elements. The .each() method allows you to execute a function against each one of the elements in the collection. So you have a bunch of elements in the page. Maybe that bunch is “every <a> tag” or “every <li> inside of

(More)…

formats

How to Create a CSS Cache Buster Using JavaScript

Use the Date() constructor to create a unique query string; ensure each GET request is not cached The other day, I was working with a customer whose iPad app was consuming an HTML page. I was making changes to the CSS, yet was not seeing them in the iPad app. I kept adding a new

(More)…

formats

Creating an HTML Option Element Using the JavaScript Option() Constructor

The little-known JavaScript Option() constructor allows you to avoid the verbose syntax of creating DOM elements We all love jQuery. Among the many awesome qualities of this library is the ability to easily create DOM elements and place them in the document without the normally verbose syntax of native JavaScript. There is a little-known feature

(More)…

formats

Associative Arrays in JavaScript

You may be finding conflicting information about associative arrays in JavaScript. Well, the answer is quite simple…. and then things start to get a little odd If you are frustrated because you have been getting different answers on this subject, I”ve got good news and bad news. The good news is, the answer is simple:

(More)…

formats

Creating JSON Data for JavaScript with PHP

in PHP.

Using PHP, you can construct your JSON data during page load JSON is a fantastic way to work with data in JavaScript. But what about getting data from PHP, in order to populate a JSON object during page load? No problem. You can simply echo your opening and closing script tags to the page, in-between

(More)…

formats

How to Use the jQuery replaceWith Method

When you need to completely remove an element and put another in its place One of the fun things about jQuery is learning about a method that introduces you to a DOM manipulation scenario you may not otherwise have thought of. The replaceWith() method allows you to chop out one piece of the page and

(More)…

formats

Using ksort() When You Need To Sort Only Array Keys

in PHP.

Sort your array by key names with ksort(), ignoring key values This function can help you out when you need to soft an array based on the names of the keys, but do not want to do any sorting of the actual element values. ksort() is efficient in that it will completely ignore the values

(More)…

formats

Removing the first element in a PHP array with array_shift()

in PHP.

Remove the first element of an array with array_shift() and return its value I have no idea why they called this one “Array Shift”. I would have thought it would be called something like array_trim_beginning() or something more intuitive. But anyway, that is what it is called. Below is some sample code that walks you

(More)…

formats

PHP Functions That Work With Function Arguments

in PHP.

When you need to work with the arguments that are passed to a function, these three built-in PHP functions can be very useful. Sometimes you may want to know how many arguments were passed to a function, or maybe you just want to grab one of the arguments. PHP has three built-in functions that allow

(More)…

formats

Using array_slice() to grab a portion of an array

in PHP.

Control exactly how many elements of an array you want to return with array_slice() If you need just a certain “slice” of an array, the array_slice() function allows you to determine which part of your array to return. array_slice() parameters There are four parameters that you use to determine exactly what is returned: Array –

(More)…

show
 
close