Incompatible jquery javascript function

Asked

Viewed 64 times

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?

  • Error: { "message": "Uncaught Referenceerror: $ is not defined", "filename": "https://stacksnippets.net/js", "lineno": 15, "colno": 9 }

  • Document.addeventlistener("Domcontentloaded", Function(){ did not resolve friend.

  • That jQuery your 1.12.4 seems to have problems. Try using this: <script&#xA; src="https://code.jquery.com/jquery-1.12.4.min.js"&#xA; integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="&#xA; crossorigin="anonymous"></script>

  • Advertising loaded normally, but other features such as the "load more" button on the home page stopped working!

  • You’re making a mistake: Cannot read property 'insertBefore' of null... probably refers to that "tesum" that does not exist on the page.

  • 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?

  • 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.

  • Edited the question Sam!

  • 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?

  • 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

  • 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.

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.