0

Now i have this code :

<!doctype html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
    var x = document.getElementById("hhh");
    $(x).append("<?php echo $v; ?> ");
</script>

<meta charset="utf-8">
<title>append demo</title>
<style>
div {
background: yellow;
}
</style>
</head>
<body>
<div id="hhh">I would like to say: </div>

<?php $v="Hello"; ?>

</body>
</html>

i need to call $v php variable in java script code i know that if i put java script code after php code it will work but if i need to put java script code in the head element like i do know and want to call any php variable in this case what should i do???

Hamza Darwesh
  • 49
  • 1
  • 1
  • 7
  • did you google for this first? – hoijui Oct 13 '15 at 12:32
  • Your code is trying to reference the element before it exists. It is like trying to eat a pizza before you make it. – epascarello Oct 13 '15 at 12:35
  • i know that if i have php and java script code in same page when it loaded the php code execute first then java script code what ever where i put php code in the page. is that right or not ? – Hamza Darwesh Oct 13 '15 at 12:58

0 Answers0