Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
EDIT
I had character blindness with this one and it was missing a dollar. Despite looking at the code in detail and running it through a number of online lint programs I didn't pick up on the missing dollar.
It was just one of those things and I'm sorry.
/EDIT
I've looked on stack overflow and the similar problems I've found appear to be when calling against an array, but I'm calling against an Id.
When I run the following I get:
Uncaught TypeError: "#consoleLog".hasClass is not a function
code:
if(msg.data.match(/^LCERROR/) || msg.data.match(/^ERROR/)) {
if (!('#consoleLog').hasClass('stop')){
setInterval(function() {
$('#consoleLog').animate( { backgroundColor : "#aa0000" }, 1000)
.animate( { backgroundColor : "black" }, 1000);
}, 100);
};
};
With my limited understanding of Jquery and Javascript I thought an Id was a valid DOM to call hasClass() with. It even has examples of it here: https://api.jquery.com/hasclass/
Any idea what might be happening here?
Purpose of the code is:
If the socket message contains ERROR or LCERROR, flash this div between black and red unless the stop class has been called.
You missed off the jQuery constructor function literal ($) in your if() statement:
if( msg.data.match(/^LCERROR/) || msg.data.match(/^ERROR/) )
{
if( ! $('#consoleLog').hasClass('stop') )
{
setInterval(function() {
$('#consoleLog').animate( { backgroundColor : "#aa0000" }, 1000).animate( { backgroundColor : "black" }, 1000);
}, 100);
}
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm getting it for the * in the chunk of code
// click function for the "See More Scores" and "See Fewer Scores" buttons
$('.show-fewer-or-more-scores').click(function ( ) {
var rowsNotFirst = $(this).closest('tbody').children('tr:gt(0)');
// unravel the scores in an animated fashion
rowsNotFirst.filter(function (idx, el) {
setTimeout(function ( ) { $(el).toggleClass("hidden"); },
50 * idx);
});
});
and I don't see why. I put it in JSHint and was not alerted of any problems that would be causing this. Full code can be seen as commit bd4629b of https://github.com/jamkin/Snake/blob/master/SnakeGame/Scripts/game.js. You can also see the live bug here although it may be fixed if you're accessing this thread a day or more later than it was posted.
Any ideas what I've done wrong?
You have an artifact hanging around at the end of the file
var idx50 = 50*idx;
rowsNotFirst.filter(function (idx, el) {
setTimeout(function (){ $(el).toggleClass("hidden");}, idx50);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am building a lightbox and am running into an issue where the following fadeIn function is firing at the same time as the fadeOut instead of afterwards.
Why is updateImage.call(this) firing at the same time as the fadeOut? Should it not fire afterwards considering it is placed as a callback?
Full code snippet
function updateImage() {
activeImage = overlayImagesBox.find('.' + this.className);
activeImage.fadeIn('slow').addClass('active-image');
}
imageLinks.on('click', function (e) {
e.preventDefault();
if (!activeImage) {
updateImage.call(this);
} else {
activeImage.removeClass('active-image').fadeOut('slow', updateImage.call(this));
activeImage = null;
}
});
As #blex mentioned in the comments the correct answer is simply passing the function as a callback instead of executing it. Thank you for the help everyone.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to accomplish a 'simple' jQuery effect.
When an user loads their dashboard, and they have a specific id (#) in the url, the dashboard should load the content assigned to that specific id.
Here is what I have so far:
var pathname = window.location.hash.substr(1);
if(pathname = loadextra){
$('.loadextra').addClass('active');
$('.load-fixed').removeClass('active');
$('.fixed-ads').hide();
$('#loader').show().html('<div class="typing_loader_holder"><div class="typing_loader"></div></div>');
setTimeout(
function()
{
$('#loader').hide();
$('.extra-ads').show();
}, 2000);
}elseif(pathname = loadfixed){
$(this).addClass('active');
$('.load-extra').removeClass('active');
$('.extra-ads').hide();
$('#loader').show().html('<div class="typing_loader_holder"><div class="typing_loader"></div></div>');
setTimeout(
function()
{
$('#loader').hide();
$('.fixed-ads').show();
}, 2000);
}else{
//do nothing
}
So, imagine an user goes to: http://website.com/user#loadextra then the code inside if(pathname = loadextra){} should be fired off - same goes for #loadfixed
Although, as it is now, if you just goes to http://website.com/user, then if(pathname = loadextra){} is fired of.
Why doesn't the if/elseif/else statement work in my code?
You have make three mistakes:
1) Replace '=' with '==' in if & elseif
2) Replace 'elseif' with 'else if'
3)Replace $(this).addClass('active'); with $('.loadfixed').addClass('active');
Try this:
if(pathname == loadextra)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am tying to add a property to a JS object inside a function. I can do it outside but not inside. Please explain. Sorry. I am missing something very basic here.
var newobj = {'prop1' : 12, 'prop2' : 25};
myfunc(newobj);
function myfunc(someobj) {
someobj.prop3 = 45;
}
This gives a syntax error.
Chances are something else is interfering because it works for me.
If you dump newobj before the function call you get:
{"prop1":12,"prop2":25}
And after the function call:
{"prop1":12,"prop2":25,"prop3":45}
As you can see, the new property has been added.
I would suggest either looking at what you have more closesly (make sure you're not copying the value and then passing it) or add some console.log call in your code as it goes through. You can also, in most of the browsers, use the debugger to step through the code to see where it may be fouled.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am getting an "Expected token: '}'" and when I add that token to the requested line i get "Unexpected token: '}'". Not really sure what I did wrong.
Any input is appreciated! Thanks!
$(document).ajaxSuccess(function(){
var currentPrice = $.trim($("#ProductPrice").text());
if(currentPrice == "%%GLOBAL_ProductPrice%%")
{
$("#ProductPrice").css('color','black');
$("#ProductPrice").removeClass("PriceChanged")
}
else
{
var scrollPos = $(window).scrollTop()
if(scrollPos >= 397) {
$("#ProductPrice").css('color','red');
$('html, body').animate({
scrollTop: $("#ProductPriceWrap").offset().top
}, 1000);
$("#ProductPriceWrap").animate({backgroundColor: "#ff0000" });
$("#ProductPriceWrap").animate({backgroundColor: "#ffffff" });
$("#ProductPrice").addClass("PriceChanged");
}
else
{
$("#ProductPriceWrap").animate({backgroundColor: "#ff0000" });
$("#ProductPriceWrap").animate({backgroundColor: "#ffffff" });
$("#ProductPrice").addClass("PriceChanged");
}
};
You last closing } actually closes this line:
if(currentPrice == "%%GLOBAL_ProductPrice%%")
{
However the expression that starts here, never gets properly closed:
$(document).ajaxSuccess(function(){
So add a }); to the end and you should be good.
Also, let this be a lesson for you in the value of consistent and proper indentation. If you paste that code into http://jsbeautifier.org/ you would see the the last line is not at an even indent level as the first line. It becomes pretty obvious then where the problem is.
If the code within that callback function was all indented, you probably would have noticed this and it would have been a quick fix.
So today you learned the value of consistent and proper indentation.