<?php
//Started or resumed the session
?>
<html>
<head>
<script type="text/javascript" src="myjavascript.js"></script>
</head>
<body>
<div class="myClass" data-attr=<?php echo $_SESSION["mySession"]?>></div>
</body>
</html>
This is my php.
In my js File, I have something like
$(function(){
alert($(".myClass").attr("data-attr"));
});
It echo the right value. I don't understand the order of execution. Because head section comes first , then my div[myclass
]. So evaluation occurs later point of time.
Is it echoes because of that I surround the code inside domready
. Is it the reason? Will it work always?