<div onclick="test(44)">anything</div>
<script>
function test(x){alert(x)};
var col=document.getElementById('Mydiv');
col.innerHTML='<div onclick="alert(2);test(123);">Text</div>';
</script>
notes:
1-alert(2); works , but test(123) not working , test(44) is working(outside innerHTML)
2- i want to use parameters inside test() functions i.e: test(123)
3-
<?php
$str3=<<< ENDd
<html>
<head>
<script type="text/javascript">
function test(x){alert(x)};
</script>
<body>
<div id="MYdiv"> this id My div</div>
<div onclick="test(44)">anything</div>
<script type="text/javascript">
var col=document.getElementById('Mydiv');
col.innerHTML='<div onclick="alert(2);test(123);">Text</div>';
</script>
</body>
</html>
ENDd;
echo $str3 ;
The above version works.
Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.
If you notice, you have shown nothing with id "Mydiv".
<div onclick="test(44)">anything</div>
< script>
function test(x){alert(x)};
var col=document.getElementById('Mydiv');
col.innerHTML='<div onclick="alert(2);test(123);">Text</div>';
< /script>
therefore : add the id = "Mydiv", as shown below:
<html>
<head>
<script type="text/javascript">
function test(x){alert(x)};
</script>
<body>
<div id="MYdiv" onclick="test(44)">anything</div>
<script type="text/javascript">
var col=document.getElementById('Mydiv');
col.innerHTML='<div onclick="alert(2);test(123);">Text</div>';
</script>
</body>
</html>
Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.
Bookmarks