0
Good night, you guys
Have this javascript function that loads a banner inside the div 'tesum', according to the amount of lines that the text has in the div, like these ADS videos advertising on news site. And another random banner at the beginning of the text inside the div 'bdads_post'. However, give the following error when using the jquery version library: http://belmontediario.com.br/wp-includes/js/jquery/jquery.js?ver=1.12.4
Error: { "message": "Uncaught Referenceerror: $ is not defined", "filename": "stacksnippets.net/js";, "lineno": 15, "colno": 9 }
With another version works well, however, other features of my site stop working, for example, the load more button at the end of the home page. www.belmontediario.com.br
https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
There is some sort of incompatibility with my code. There is another way to do this?
Obirgado by the attention!
$(function(){
var banner = ["<img src='http://1.bp.blogspot.com/-iFFHRIIu-OQ/WeQhVKLaqZI/AAAAAAAAhRM/poHm7XyVpfoK2OE-bR-D21wQrMU1W5RzgCK4BGAYYCw/s1600/madferro.gif' alt=''>", "<img src='http://3.bp.blogspot.com/-B84mYgVTaQQ/Utfu9prTnnI/AAAAAAAABtM/KdTqQzNS2Ec/s1600/ducarmin.gif' width='300' alt=''>"];
var bannerPost = banner[Math.floor(Math.random() * banner.length)];
$("#bdads_post").append(new Array(1 + 1).join(bannerPost));
});
$(function(){
var newImage = document.createElement('p');
var img = document.createElement('div');
img.innerHTML = '<img src="http://3.bp.blogspot.com/-nCxwwr5kcUM/WM7z-Gqi2FI/AAAAAAAAd2g/e30MQRv-EoUDwDIsAZyzCa0VqoaSPd6PQCK4B/s1600/ph-turismo.gif"/>';
newImage.appendChild(img);
newImage.id = 'phtur';
var image = document.getElementById("tesum");
image.insertBefore(newImage, image.childNodes[26]);
});
$(function(){
$('#phtur').hide().delay(20000).slideToggle('slow');
$('#phtur').click(function(){
$("#phtur").slideToggle('slow');
});
});
<div id='tesum'>
<div id='bdads_post'></div>
<p>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</p>
<p>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</p>
<p>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</p>
</div>
What mistake it makes?
– Sam
Error: { "message": "Uncaught Referenceerror: $ is not defined", "filename": "https://stacksnippets.net/js", "lineno": 15, "colno": 9 }
– Elson Jackson
Document.addeventlistener("Domcontentloaded", Function(){ did not resolve friend.
– Elson Jackson
That jQuery your 1.12.4 seems to have problems. Try using this:
<script
 src="https://code.jquery.com/jquery-1.12.4.min.js"
 integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
 crossorigin="anonymous"></script>
– Sam
Advertising loaded normally, but other features such as the "load more" button on the home page stopped working!
– Elson Jackson
You’re making a mistake:
Cannot read property 'insertBefore' of null
... probably refers to that"tesum"
that does not exist on the page.– Sam
the "tesum" involves the text of the post, it exists yes. The template of my post eh essa in the html editor: <div id="tesum"> text of the news </div>. It refers to the library, when I update my code library to and the other things work, and virce versa. Maybe I have to update my javascritp code or make it different?
– Elson Jackson
If any function does not work in one version or another, it is a problem in the event, as you said. It would be interesting to ask the question an example of what works and what doesn’t work in the respective versions of jQuery.
– Sam
Edited the question Sam!
– Elson Jackson
I suggest using the latest version of jQuery and look for the other problems and try to update them, but for that you need to know the code. Or are plugins?
– Sam
Are codes! That code there I did! Already the other functionalities are the theme itself (wordpress). Here is the code in operation: http://bn01.blogspot.com/2018/08/correios-de-pernambuco-podem-deflagrar-greve.html
– Elson Jackson
This can be a precedence problem. Inspect the page and see if your code has not been loaded before jQuery. Or if you are not loading two jQuery on the page, because if this happens the plugins of the first are overwritten.
– fernandosavio