Category Archives: featured

jQuery – accessing a child element

Let’s assume you have a <div> element with 20 <a> tags inside, and each <a> tag has a <span> somewhere inside it. If you’d like to access all those spans you should use this jQuery line:

$('div a').children(':first-child')

Common mistake is to query like that:

$('div a:first-child')

but that is completely other thing, and will return the first <a> tag, not the <span> inside all of them.

Dependency Injection

Fabien Potencier writes about the Dependency Injection

With a series of interesting posts Fabien Potencier explains what is a dependency injection and how to use it. Actually as the author says almost everyone of us has used it without even know it’s called ‘dependency injection’. Follow these two links to understand this technique by a given collection of very good examples:

  1. What is dependency injection
  2. Do you need a dependency injection container?

Related Links

  1. Martin Fowler – Inversion of Control Containers and the Dependency Injection pattern

Lambda functions in PHP?

What’s new in PHP 5.3.

When I heart about the new PHP 5.3 feature – the lambda functions I was really surprised. Yes really after we have in JavaScript such a powerfull tool, why not having it in PHP. Other new feature, waited so much, are the namespaces.

Anonymous Functions?

The anonymous functions is really a functional programming language feature such as scheme. There are lots of talks about the functional nature of JavaScript, but PHP was really different.

What about anonymous objects

I’d like to see anonymous objects, yet again like in JS, in PHP. This is really powerfull, I hope more programmers would like to see such features in PHP.

Related Links

  1. Namespaces has PHP 5.3. (Or the other way around)
  2. What’s new in PHP 5.3.
  3. Lambda functions are coming to PHP

CSS color units

What is a color unit?

By saying CSS units some may guess this is related to the mesurement units. In fact beside the mesurment there is also a color units defined in CSS.

The most used is the #rrggbb, where the three channels red, green and blue are represented with hexadecimals, i.e. #fa03cd, or the short way #rgb. In fact #cc00cc will be the same with #c0c, but #cc02ca is not like #c0c.

Some purple #FA03CD

Actually there are other ways to set a color on an element. Such a way is to set the rgb(255,255,255), which is white. You can easyly transform the hexadecimals to decimals, it’s obvious that xFF is 255 in decimals.

There are five ways to set up a color with CSS

In general there are five ways to set up color with CSS:

#rrggbb ( for red, green and blue as mentioned – #FF00FA )

#rgb ( short way to say #rrggbb – #CC3 )

rgb( x, y, z ) – ( where x, y and z are numbers between 0 and 255 – rgb( 255, 255, 255) )

rgb( x, y, z ) – ( where x, y and z are percents between 0 and 100 – rgb( 100%, 20%, 23%) )

The Windows palette

There is a fift way to set a color on a element with CSS, with predefined colors corresponding to the MS Windows VGA palette, and they are:

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow