Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
112
rated 0 times [  114] [ 2]  / answers: 1 / hits: 26685  / 12 Years ago, sun, january 27, 2013, 12:00:00

Can I please have some help to call a function that is created in Javascript when a reference is made to a DIV in HTML.



Here is my function:



        function testFunction()
{
alert(Test);
}


I would like the testFunction to be called when the following reference is made in HTML:



<div id=testFunction> 


Can I please have some help to do this?


More From » function

 Answers
47

You can attach the call to a click handler:



In markup:



<div id=testFunction onclick=testFunction()> 


Or inside your script block:



function testFunction() {
alert(Test);
}

var el = document.getElementById(testFunction);
el.onclick = testFunction;

[#80591] Friday, January 25, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isaacvalentinn

Total Points: 325
Total Questions: 120
Total Answers: 131

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
isaacvalentinn questions
Mon, Jan 18, 21, 00:00, 3 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Wed, Sep 23, 20, 00:00, 4 Years ago
;