I want to display my JavaScript variable inside div col. I just can't get it displayed. Even with inspector it doesn't have a value. However, if I display it outside of every div, so in the beginning of the page it works..
$(document).ready(function() {
var firma = "test d.o.o.";
document.getElementById("insert").innerHTML = firma;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<p><span style="z-index: 9999 !important;" id="insert"></span></p>
</div>
Here is code: http://jsfiddle.net/th5wydn1/10/
Thank you for your help. Greetings
CodePudding user response:
If all you did is copy and paste the code, your local page doesn't have jQuery.
Either add that, or replace your one line of jQuery code with native Javascript:
document.addEventListener('DOMContentLoaded', function() {
var firma = "test d.o.o.";
document.getElementById("insert").innerHTML = firma;
});
CodePudding user response:
You are using jquery Syntax. Means you need include the JQuery Lib. For example add this CDN script link above your closing body tag.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
$(document).ready(function() {
var firma = "test d.o.o.";
document.getElementById("insert").innerHTML = firma;
});
<div>
<p><span style="z-index: 9999 !important;" id="insert"></span></p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<p><span style="z-index: 9999 !important;" id="insert"></span></p>
</div>
CodePudding user response:
Hello change "insert" word , maybe this keyword,or busy
<span style="z-index: 9999 !important;" id="_insert"></span>
$().ready(function() {
const firma = "TEST";
document.getElementById("_insert").innerHTML = firma;
});
