Archive for the ‘Javascript’ Category

Check object exists or not

April 12, 2011 Leave a comment

We can check through javascript whether html element exists or not.
create this function
function checkobject(obj) {
if (document.getElementById(obj)) {
return true;
}else {
return false;

Pass element’s id in this function, this function return ‘true’ if that element exists on web page other wise return false.



How to get which element clicked

April 11, 2011 Leave a comment

We can find out which element clicked on web document.
First we need to create a function i.e
function gotElement(){
var ele = arguments[0] || window.event, origEl = || ev.srcElement;
alert(ele.tagName);//Getting  tag name of element.

Now call this function like this…
document.onclick = gotElement();

Whenever user click on click on document then a alert will open that contains tag name.

How to check browser has javascript enabled or not

April 7, 2011 Leave a comment

The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “”&gt;

<html xmlns=”; xml:lang=”en”>
<meta http-equiv=”refresh” content=”0;url=”/>

Add and Remove element

October 28, 2010 1 comment

We can add any element through javascript. It is so simple and easy.  Use below script to add and remove a div element.

<title>Add Element</title>
<script language=”javascript”>
this.num = 1;
function addElement(){
$top = document.getElementById(‘top’);
newId = document.createElement(‘div’);
id = ‘my’+this.num;
newId.setAttribute(‘id’, id );
newId.innerHTML = “<a href=’javascript:void(0); ‘ onclick=’removedThis( “+id +”)’ >Added Element”+id+”</a>”;
function removedThis( id ){
var d = document.getElementById(‘top’);
<input type=”button” name=”button” value=”Add Element” onclick=”addElement()” />
<div id=”top” ></div>

Print content of a element

November 25, 2009 Leave a comment

If you want to print content of a html element, with the help of javascript you can do this.  You need to call  this function and pass a argument ( element id ). Take a look of this function.

<script type=”text/javascript”>
function printSelection(node){
var content=node.innerHTML
var”,’print_content’,’width=12800,height=1000, scrollbars=1′);;
pwin.document.write(‘<html><body onload=”window.print()”>’+content+'</body></html>’);

Now time to call this function. I called this function in a hyperlink like this.
<a href=”” onclick=”printSelection(document.getElementById(‘foo’));return false”>Print</a>

When you click on “Print” then print dialog appears give print command and enjoy this script.

Click here

Categories: Javascript


November 9, 2009 Leave a comment
1.) document.getElementById(‘id’): You can access virtually any element in            the DOM. Here is the syntax …
a.) var obj    =    document.getElementById(‘id’);
alert(obj.value); {get value of a element}
alert(obj.title);  {get title of a element}’red’;  {Change color of a element}
b.) var obj    =    document.getElementById(‘id’).value;{get value of a element}
var obj1  =    document.getElementById(‘id).title; {get title of a element}


The different node methods available through DOM manipulation are as follows:
Categories: Javascript

Object Oriented JavaScript

November 4, 2009 Leave a comment

Creating a class

Use object oriented javascript.
Below code write in .js file.
First of all declare a class. In JavaScript  class declaration same as function.
Let create a class in JavaScript
function MyClass(){
Now create a function in this class
function MyClass(){
this.firstFunction = firstFunction;
function firstFunction(){
alert(“I am from class”);
Now call the class function through object.  So we need to create object that
var obj = new MyClass();

OutPut: A alert msg “I am from class”.

%d bloggers like this: