I am having difficulty in place my jquery variable inside my html tag. For some reason the variable is being displayed outside of my div.
I have the following code:
<script>
$(document).ready(function() {
setInterval(function() {
var sec = 30
var timer = setInterval(function() {
$('#hideMsg span').html(sec--);
if (sec == -1) {
$('#hideMsg').fadeOut('fast');
clearInterval(timer);
}
}, 1000);
}, 2000);
});
</script>
<script>
$(document).ready(function() {
setInterval(function() {
var randomnumber = '<div id="hideMsg"><span>30</span></div>';
$('#warning_show').html('<div id="message_box2"><h23>Warning!</h23><p>Your account has been Inactive for some time. You will be logged out in ' + randomnumber + ' seconds.</p><div class="boxclose" id="boxclose" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">✖</div></div>');
}, 3000);
});
</script>
<div id="warning_show"></div>
This produces the following result:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| |
| Time runs out in |
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
30
seconds
What I want to have is:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| |
| Time runs out in 30 seconds |
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
Can someone please show me where I am going wrong?