Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
-5
rated 0 times [  2] [ 7]  / answers: 1 / hits: 35347  / 15 Years ago, wed, june 3, 2009, 12:00:00
<script>
function Hello(){
var caller = arguments.callee.caller;
alert( caller );
}
</script>

<input type=button id=btnHello value=Hello onclick=Hello() />


How to get the button id from the the Hello function above with out passing the any argument in the Hello function


More From » javascript

 Answers
94

An event object is passed to the Hello function automatically. You need to receive it as an argument and then do some cross-platform work to grab the element. A JS framework will help you out here.



function Hello(e){
var caller = e.target || e.srcElement;
console.log( caller );
}


EDIT

+1 Andrew's comment below. Use addEventListener and attachEvent for best practice.


[#99398] Friday, May 29, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leslijessalyng

Total Points: 650
Total Questions: 85
Total Answers: 109

Location: Croatia
Member since Mon, Sep 6, 2021
3 Years ago
leslijessalyng questions
Fri, Feb 21, 20, 00:00, 4 Years ago
Tue, Jul 30, 19, 00:00, 5 Years ago
Fri, Jul 5, 19, 00:00, 5 Years ago
Wed, Mar 13, 19, 00:00, 5 Years ago
;