0

For example, how would one pass data through the argument myvar with the following code:

<script>
function test(myvar) {
  alert('Testing: ' + myvar);
}
</script>

<div id="testDiv"> ... Text ... </div>


<script>
document.getElementById("testDiv").onclick = test;
</script>
reformed
  • 4,505
  • 11
  • 62
  • 88

1 Answers1

0

You mean like this?

document.getElementById("testDiv").onclick = function() {
   test("hello there");
};
MightyPork
  • 18,270
  • 10
  • 79
  • 133
  • The parameter needs to be varying, not hard-coded. So, for example, if you have a table of rows, each row index could be passed in the `myvar` parameter. – reformed Aug 03 '13 at 19:50
  • 1
    @reformed: You can do whatever you want within the event handler. For example getting the row index it pass it to `test`. – Felix Kling Aug 03 '13 at 20:20