Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing a local variable within the function

Tags:

javascript

By clicking on the following DIV, nothing happens. Where is the error ?

<div onclick="function dummy(that) { alert(that.toString())}" class="next">></div>

Please help.

like image 231
user160820 Avatar asked May 17 '26 23:05

user160820


1 Answers

You are defining dummy but not calling it. I don't think it works that way, not in the HTML onclick property anyway.

I suggest you move dummy() into a separate code block:

<script type='text/javascript'>
function dummy(that) { alert(that.toString())}
</script>

and then:

<div onclick="dummy(this);" class="next">></div>

or attach the function programmatically like so:

document.getElementById("myDummyDIV").onclick = function(event) { ..... }
like image 152
Pekka Avatar answered May 20 '26 12:05

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!