Skip navigation

Monthly Archives: November 2009


You can add content to a web page using css !!!

Using content property in combination with :before and :after pseudo-elements, you can add content to any element. Of course Opera support this with all elements (without pseudo). IE6, IE7 not supports this property.

/* CSS */
#box:before {
content: "This text is before the box";
}
#box:after {
content: "This text is after the box";
}

<!-- HTML -->
<div id="box">I'm inside box</div>
  • Though it is not advisable to generate content using css because css is for presentation, rather use JavaScript for that.
  • You can’t use html inside content; only text.

Note: I posted here because it surprises ME to know css can generate content. My fellow UI friends may aware about this.


To understand the  constructor, consider the following code

// constructor function definition
function sum(a,b){
    this.total=0;
    this.total = a + b;
    return this.total;
}

// create object using sum constructor
var sal = new sum(3,3);

alert(sal.total);  // 6
alert(sal.constructor)  // displays function definition above

Now sal is object of type sum.

Interesting part is you can create sum object using sal though constructor property. Here is how…

var sal1 = new sal.constructor(5,5);
alert(sal1.total);  // 10

JavaScript reference variable references only the final referred object, not a reference itself. When reading this first time, I got confused little.

Consider the JavaScript code below

// declare a variable
var aNames;
// create array and assign reference to aNames
aNames = Array("vkanakaraj", "rajakvk", "javascript");
// declare another variable and reference it to aNames
refNames = aNames;
// check its working
alert(refNames[0]);
// now assign another array to aNames
aNames = Array(22,25,10);
// still points to vkanakaraj
alert(refNames[0]);

got it?