hasClass is not a function [closed] - javascript

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
I'm writing a simple jquery code to animation an element on my page:
curent
$('#tgs-nav-icon').on('click', function() {
var $nav = (".canvas-menu-content");
var bounceInRight = "bounceInRight animated";
if(! $nav.hasClass(bounceInRight) ) {
$nav.addClass(bounceInRight);
}
else {
$nav.removeClass(bounceInRight);
}
});
Uncaught TypeError: nav.hasclass is not a function
I tried testing this to see where I went wrong and this code comes back false as it should:
var help = $( ".canvas-menu-content" );
console.log(help.hasClass("foo"));
I can't figure out why the if statement is throwing me the error.
I've tried doing some research, but none of the previous questions seem to answer my issue.

You're assigning $nav to the string ".canvas-menu-content" here:
var $nav = (".canvas-menu-content"); // $nav is now '.canvas-menu-content'
Assign it to a jQuery object instead:
var $nav = $(".canvas-menu-content"); // $nav is now a jQuery object containing all
// elements with class canvas-menu-content

Related

Error javascript [closed]

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
In console, I have this error. I use the latest jquery 3.1.
How to rectify this element ?
Thank you
typeError: window.on is not a function
<script>(window).on('load', function (){var maxHeight=0;$(".equal-height").each(function(){if($(this).height()>maxHeight){maxHeight=$(this).height();}});$(".equal-height").height(maxHeight);});</script>
You need to use $ as a prefix to the (window) part of your script or it won't be a JQuery object.
<script>$(window).on('load', function (){var maxHeight=0;$(".equal-height").each(function(){if($(this).height()>maxHeight){maxHeight=$(this).height();}});$(".equal-height").height(maxHeight);});</script>
You're missing the $ symbol at the start of your code, this is the shorthand for jQuery and needs to be used when using any of the jQuery library. Your complete code becomes:
$(window).load(function() {
var maxHeight = 0;
$(".equal-height").each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(".equal-height").height(maxHeight);
};
This is also the same as
jQuery(window).load(function() {
var maxHeight = 0;
$(".equal-height").each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$(".equal-height").height(maxHeight);
};

Why am I getting "Uncaught SyntaxError: Unexpected token *" here? [closed]

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);

how to find and replace text url with links in jquery [closed]

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
Hi I want to find text url in my editor and convert them to anchor tag links using jquery.
here is my code
function urlify(text) {
var urlRegex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
return text.replace(urlRegex, function(url) {
return '' + url + '';
})
}
$("#queEditor").bind('input propertychange', function(){
var url = urlify($("#queEditor").text);
console.log(url);
});
But it's giving an error undefined function text. Could someone help me rectify this?
Since .text() is a function you need to use () when you want to invoke it.
$("#queEditor").text(); //Notice ()

Javascript String.replace [closed]

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
Can someone please explain why this code isn't working?
(it has been simplified for this example)
$(document).ready(function () {
var test = 'broken';
test = test.replace('broken','working');
console.log(test); // working
var field = $('[for="tournament_name"]').html();
console.log(field); // Tournament Name:
console.log(typeof field); // string
field = field.relpace(':',''); // Uncaught TypeError: undefined is not a function
});
I don't understand why it is saying replace() is undefined?
I did read through the docs, what am I missing here?
Maybe it's a typo:
relpace --> replace

Matching the string [closed]

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'm having some difficulty with looping through an array and matching it with a string, I have a search box with an autosuggest, when the user types the suggested string appears.
So the idea is to alert when the matches the variable, here is what I have so far, any help would be great.
var DomainCentral = "DomainCentral";
var DomainGuard = "DomainGuard";
$(function() {
var availableTags = [
DomainCentral,
DomainGuard
];
$( "input#tags" ).autocomplete({
source: availableTags
});
for (var i in availableTags){
if (availableTags == DomainCentral) {
alert('hello');
}
}
});
Looks like you need to listen to an event, and do this check when that event happens. This looks like the right event, tho i haven't tried it: http://api.jqueryui.com/autocomplete/#event-response You'll need to read the input, i.e. $('input#tags').val(), and check that value against your array inside the event listener.

Categories

Resources