1
I have a very unusual and strange problem... I am using the Jquery library, however, it is not being interpreted correctly, the problem is not in the code itself, ie, when I do the code even without syntax error or semantics the code is not fired, however, when I put the same code in Codepen works correctly.
No code is working
I already tried:
<!-- Baixar a biblioteca -->
<!-- HTML -->
<div class="col">
<div id="pallete1" style="width: auto;height: 195px;background-color:
#316E1F"></div>
</div>
<script src="tmp.js"></script>
<script src="jquery-3.3.1.min.js"></script>
/*
* tmp.js
*/
$(document).ready(function(){
$("#pallete1").click(function(){
$(this).css("background-color", "blue");
});
});
<!-- Via CDN -->
<!-- HTML -->
<div class="col">
<div id="pallete1" style="width: auto;height: 195px;background-color:
#316E1F"></div>
</div>
<script src="tmp.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-
q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
/*
* tmp.js
*/
$(document).ready(function(){
$("#pallete1").click(function(){
$(this).css("background-color", "blue");
});
});
<!-- Arquivo unico -->
<!-- HTML -->
<div class="col">
<div id="pallete1" style="width: auto;height: 195px;background-color:
#316E1F"></div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#pallete1").click(function(){
$(this).css("background-color", "blue");
});
});
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-
q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
Noting that I tested in the browsers Edge, Firefox and Chrome and did not work, I also tested with a server and opening a file directly from the browser and on another computer here in the company where I work!
Some important details:
- The same code works on Codepen
- Features that require Bootstrap Javascript work, less Tooltips and Popovers elements
- Sometimes the code cocks, but it stops and comes back whenever it wants
- The same logic only works with Vanillajs
What I need:
I need to codate in Jquery and use the features of Bootstrap and with you, however, only using Codepen but I want to save and test my codes on the pc
Thank you all
Try reversing the inclusion order of jquery and tmp. If tmp depends on jquery, it should be included later.
– bfavaretto
What if you use "width=100%"? Is the DIV not running out of width, preventing the click event? Just a hypothesis...
– Rodrigo Tognin
@bfavaretto as soon as I read his question I thought the same thing as you and took the liberty to give an answer. If you want to answer it directly tell me that I remove my answer ok. []s
– hugocsl