Here you can see the working code - http://jsfiddle.net/gryzzly/YxnEQ/
Please note that you need an element with the identifier "sample" that will be present in your document when you run the above code. In addition, this points to a jQuery object, so to get the identifier of the elements, you need to use one of the following values:
alert( this[0].id );
or
alert( this.attr('id') );
The first is preferable because it is faster.
Misha reyzlin
source share