Error code with javascript, how to change it? - javascript

Either my javascript or my template is broken.
This is my javascript to change error messages. I cannot change my template, because it is not accessible.
$(function() {
$.ajaxSetup({complete: function() {
$("errorExplanation:contains('1')").html('1 error has occurred');;}}) });
This is the part of the website that refuses to be translated:
The code of the page
What am I doing wrong?

Related

Javascript File Not Functioning in Wordpress w/ Proper Enqueueing in Functions.php

My JS file is being properly called in my functions.php file because there is no error in the console when I inspect element. Why is this js code not running? Do I need to wrap the function? Everything I tired did not work. I am no js expert, but I think this code should work... It worked in my codepen.
Note: I am calling the script in the footer. Should I be calling it in my header since it is for my mobile header menu?
// Mobile Menu
$('.hamburger').on('click', function () {
$('.main-navigation').toggleClass('open');
});
It should work fine via the footer. You could try wrapping it in a
$( document ).ready(function() {
$('.hamburger').on('click', function () {
$('.main-navigation').toggleClass('open');
});
});
How are you calling the jQuery? Are you placing it in a shortcode to a function in your functions.php, or directly in a tag inside the footer?
Last question (sorry, i'm new - and thorough): Have you checked your console? Any other Java errors?
sorry this is a mess, I am trying to figure out the formatting for answers/comments

Jquery conflict in Wordpress after move into another hosting

i was looking for some solution it but i didnt find anything.
I think its jquery conflict. I have installed smart-slider, and after move my Wordpress into another hosting its just stopped working. My browser shows me: "undefined its not a function", and my code (generated by plugin ofc):
<script>
njQuery(document).ready(function () {
njQuery('#nextend-smart-slider-1').smartslider({parameters});
});
</script>
I was trying to change it into $.('#next.. or jQuery('#next, but it still broke.
Any ideas?
You can change the code to be a simple jQuery. And not the njQuery.
<script>
jQuery(document).ready(function () {
jQuery('#nextend-smart-slider-1').smartslider({parameters});
});
</script>
Otherwise it won't work. Or else, just make sure that the server has a variable or a script file to handle the njQuery too.

Counting the number div loaded from external php file

I have two php files, child.php and parent.php. Child.php generates div. Now, the parent.php calls child.php to be loaded in <div id='divContainer'>. Now, I need to count the div inside the divContainer. Is it possible?
I tried something like this:
$(document).ready(function () {
var total_record = $('#divContainer > div').length;
alert(total_record);
});
But it's not working. Even an empty alert is not popping out.
Can someone here, help me on this? THank you!
There's a syntax error:
)};
Should be:
});
Often if you are not getting any output/result at all when expected, it is down to a syntax error which will cause the browser to be unable to parse and execute the code. For future debugging, use the error console as this normally points out any errors with a decent description of the problem.

How to rectify the no wrap(head) JavaScript from jsFiddle to HTML to get it working

Few days ago, I posted a query regarding a concept of a slide.
stumbled upon this exact concept right here.
http://jsfiddle.net/JCQ6Q/15/
However, I'm facing a problem.
in Js Fiddle, everything seems to be working out fine.
but When I compile it on the HTML editor software on my local host, It doesn't run :(
The images are stack on top of one another & a scroll bar appears.
It may be because on JsFiddle, the framework is put to no wrap(head)
If Its put to the default onLoad , the same thing happens as it does in my HTML
any inputs on how i can correctly put the javascript on the HTML?
The error in the console is this:
Uncaught TypeError: Object [object Object] has no method 'anythingSlider'
Your plugin script is being included too late (.ready() executes before .load()). Make sure to structure your HTML something like this:
<script src="plugin.js"></script>
<script>
$(function () {
$('#slider').anythingSlider({
autoPlay: true,
autoPlayLocked: true,
buildStartStop: false
})
});
</script>
Did you test with :
$(document).ready(function() {
// your code
});
It seems that it works on jsfiddle link

jQuery not working in IE - simplacart implementation

I'm relatively new to jQuery so apologies if the answer is obvious.
I have a shopping cart using simpleCart js, when adding an item to the cart in FF and Chrome everything runs smoothly but IE(9) doesn't seem to manage it.
http://www.peaknature.co.uk/cart/
The main piece of script is:
UPDATED
$(document).ready(function() {
$(".simpleCart_shelfItem").hover(function(event) {
$(this).find('.tooltip').stop(true,true).show();
});
$(".simpleCart_shelfItem").mouseleave(function(event) {
$(this).find('.tooltip').stop(true,true).fadeOut(500);
});
//Cart info (all items in cart)
$(".cartInfo").toggle(function(){
$("#cartPopover").show();
$(".cartInfo").addClass('open');
}, function(){
$("#cartPopover").hide();
$(".cartInfo").removeClass('open');
});
$(".shelf .simpleCart_shelfItem:eq(0)").css('left', '20px');
$(".shelf .simpleCart_shelfItem:eq(1)").css('left', '250px');
$(".shelf .simpleCart_shelfItem:eq(2)").css('left', '480px');
$(".shelf .simpleCart_shelfItem:eq(3)").css('left', '710px');
$(".shelf .simpleCart_shelfItem:eq(4)").css('left', '20px').css('top', '170px');
});
I know IE can be funny with selectors etc but I'm not sure what's wrong.
Any help is much appreciated.
Chris
I believe what is happening is the simplecart logic is running before its ready, add this round all your code (and remove the script tags).
$(document).ready(function() {
//All your code here.
});
This will sure everything is loaded before attempting to use it.
UPDATE
After looking at ie9 console it shows the following error
SEC7112: Script from https://raw.github.com/
wojodesign/simplecart-js/master/simpleCart.js was blocked due to mime type mismatch
This is likely due to the fact that raw.github provides a raw text file to your without telling you it is a js file.
Try setting the type="text/javascript" on the <script></script> tags to rectify
On a side note I am unsure if you are infact the owner of wojodesigns or not however it could be better to use a local version (local to your server) to ensure it not changed without you knowing (even more important if it anything to do with ecommerce).
Hope this helps

Categories

Resources