Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
how I get source element's tagName?
2 Posts
how I get source element's tagName?

Hello all, I have a problem that how i get source element from event 'e' in following example.

I given onfocus event on body tag.

function for "handleKeyboardShortcuts" is fallows -------

function handleKeyboardShortcuts(e) {

var code;
if (!e) e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
   **********************************
    var sourceElement = e.srcElement.tagName;
    alert("source element: "+ sourceElement);
   ********************************
var character = String.fromCharCode(code);

//key = 'space bar'
if(code == 32 || character == "")
{
         //I do something here.
     }

}

I used e.srcElement.tagName; but i don't get source element.

Can any one tell me how i get it?

Thanks, vikas.

Read the Prototype docs: http://prototypejs.org/api/event/observe Prototype provides a cross-browser method for finding the target element from the event.

2 Posts
Login to add your message