PDA

View Full Version : GetFocus() Function?



NeoMoon
Jun 30th, 2009, 07:30 AM
Is there a function that returns the element that is currently being focused on?

mike182uk
Jun 30th, 2009, 09:51 AM
JS:


function getElementOnFocus(e){
var e = document.getElementById(e);
alert(e);
return e;
}



HMTL:


<input type="text" id="test" onfocus="getElementOnFocus(id);" />
<input type="text" id="test2"/>
<input type="text" id="test3"/>



this is a pretty crude example. but you would be able to identify or return an element using the onfocus and onblur event handlers. obviously you would not put the onfocus inline (well you could if you really wanted to), you would attach an event litstenener or wot not. and make it cross browser.