Monday, May 24, 2010

Some more uses of '$' in prototype javascript

Hi all,

We are all using the '$' in prototype javascript to get the object of the matched DOM element by using id of the element.

Say for example:

the page has the div element

content inside the div element


To get the object of the div element we are using the '$'.

$('container') => returns the object of the DOM element.

$A/$W/$F => are also available but rarely used..

the below lines explain the use of the $A/$W/$F

// converts a string into array, each element is taken as a count
>>> $A('1')
['1']
>>> $A('123')
["1", "2", "3"]

// converts a string into array, it takes whitespace as delimiters
>>> $w('1 2 3')
["1", "2", "3"]

// used to get values of text field which is located inside any forms
// same as Form.Element.getValue
>>> $F('press_room_url')

So start using these commands makes the code simpler..


Thanks,
Vadivelan

No comments:

Post a Comment