I have the following jquery script that I want to work
<?php
$script=<<<SCRIPT
$("#btn").click(function(){
alert("hello");
});
SCRIPT;
$html=<<<HTML
<input type="button" id="btn" value="clickme">
HTML;
?>
<script type="text/javascript">
$.globalEval('$("#divhoho").prepend("<?php echo $script; ?><script><?php echo $html; ?></script>");');
</script>
<div id='divhoho'></div>
The problem is the event handler that I prepend on the div does not work on the html I prepended also
I also tried the jquery live()
<?php
$script=<<<SCRIPT
$("#btn").live({
click: function(){
alert("hello");
}
});
SCRIPT;
$html=<<<HTML
<input type="button" id="btn" value="clickme">
HTML;
?>
<script type="text/javascript">
$.globalEval('$("#divhoho").prepend("<?php echo $script; ?><script><?php echo $html; ?></script>");');
</script>
<div id='divhoho'></div>
and still it does not work… is this algorithm possible to work? thanks
P.S. The values in the php heredocs are already cleared in newlines so it will not produce any javascript errors
Try this,