add class to parent on click with jQuery - javascript

I currently have this, it was working in jsFiddle, though its giving me errors, and not working when I use it outside of fiddle.
$('.down-photo').click(function() {
$(this).parent('.img-mask').toggleClass('hide');
});​
Firebug says:
Uncaught SyntaxError: Unexpected Token ILLEGAL
I'm newer to javascript and jQuery so I'm not sure what's wrong or what that error means.
Thanks!

In the code in your question there is a non-printing character after the last semicolon. It seems to be character 8203, a Unicode zero-width space. That's the illegal token that Firebug is telling you about.
You'll notice, if you edit the text in your question, that if you put the cursor to the left of that last semicolon and then press the right arrow a few times it takes one more keypress than you'd expect to get to the next line - that's the character I mean.
Delete that character, or manually retype the line (rather than copy/pasting), and it should be fine.

I fixed your error. $.appendTo() takes a selector, not a jquery object.
Try this:
http://jsfiddle.net/dvCmR/133/ (line 4)

Related

Cleave.js error in getPostDelimiter() when entering first character into input

While implementing cleave.js for credit card formatting of an input field created as a custom element using litElement I ran into this error when I type the first character into the input but no issue with subsequent characters.
cleave-esm.js:712 Uncaught TypeError: Cannot read property 'slice' of undefined
at Object.getPostDelimiter (cleave-esm.js:712)
at Cleave.onChange (cleave-esm.js:1244)
I tracked it down as far as that it seems getPostDelimiter() is taking a value that is the previous character typed. Since I am looking at the first character this function fails when it tries to execute cleave-esm.js:712.
return value.slice(-delimiter.length) === delimiter ? delimiter : '';
I'm not sure if there is something I can do in my implementation to resolve this or if it's just a bug in Cleave.js that needs to be fixed.
It seems it's an issue introduced in 1.6.0 release.
If you can stick to a previous version, that should get you going.

How do I create line breaks in JavaScript?

I am using some code I found on this site and need to know how to insert a line break instead of a comma.
I have tried using \n as follows:
if(flg>0){
app.alert('There are '+flg+' fields that require a value\n\n'**+ fArr,3**)
}
But keep getting a syntax error. What am I doing wrong?
Adding the following text:
"\n"
on where you want the line break, definitely causes a line break. E.g. onclick="alert('Hi \n How are you?')"
You may be getting a syntax error because how you've entered asterisks. Try wrapping them with quotation marks too?
\n is what you require to get a line break and is correct. Your syntax error occurs because alert('There are '+flg+' fields that require a value\n\n'**+ fArr,3**) is not a valid method - unless you have overwritten it, alert() is a method that only takes one argument - a string.
'There are '+flg+' fields that require a value\n\n'**+ fArr,3** is not a valid string. Try instead 'There are '+flg+' fields that require a value\n\n**'+ fArr+',3**'.

Illegal character in javascript

I've been debugging this for hours already but really can't find the culprit of this illegal character. My javascript looks fine. This is my code.
this.PrintApplication = function Test$PrintApplication(ApplicationID, callback) {
$.post("/Application/PrintApplication/" + ApplicationID,
function (data) {
var result = eval(data);
if (result.error) {
DisplayPrompt("Error", result.message);
return;
}
else {
callback(result.data);
}
});
};
In firebug it shows.
In inspect in chrome and in console it redirects me in this line.
Any idea where is that illegal character is in my function?
It looks like you've got some unprintable characters in your source. Do you have a way of displaying those in your editor and deleting them? Deleting and retyping the line might fix it as well.
If that's not the case, maybe what you're trying to evaluate isn't JavaScript at all. You could be running that on an image or some kind of binary data.
Remember to be extra super careful when using eval on data that comes from an external source. If you can avoid doing it, avoid it.
This might be due to the reason that you have copied the code from web and simply pasted in your file. Try typing the same code to the file.
This error occurs due to UTF-8 characters.
This could happen if you normally type with different alphabets. For example the Γreek question mark ; is a different ASCII character from the English semi colon ;. If you use the first, you'll get exactly this error.
One solution is to copy paste your method to notepad and then back to your IDE.
This will often normalise and eliminate weird characters that might be hidden or undecipherable.

selenium IDE javascript replace: Throw an exception: missing ; before statement

I wrote a test using selenium IDE, I need to compare two text that MAY contain the
character, if the strings are equal, it skips to a label. the comparison command
<td>gotoIf</td>
<td>'${var1}'=='${var2}'</td>
<td>skip</td>
works if the character above is not there, but fails with
[error] Threw an exception: missing ; before statement` otherwise
I tried to write a replace statement supposed to replace ' with a blank space (since I don't care if is there or not):
<td>storeEval</td>
<td>javascript{storedVars.var1.replace("\'"," ");}</td>
<td>var1</td>
but it always fails with the same error as above.
what am I missing? can anyone help me?
I took user extension js from here. Can you try with double quote instead of single quote in gotoIf command? It works for me. Please refer my screenshot below.
<td>gotoIf</td>
<td>"${var1}"=="${var2}"</td>
<td>skip</td>

jQuery illegal character showing up when trying to add jQuery and bootstrap

The illegal characters seem to be in Japanese? How did this happen?
here is my blank html with jQuery/bootstrap included, firebug gives me:
illegal character line 1 jQuery..min.js
...潡琨昮捳猨愬挫扸孥崩⥼簰⤻牥瑵牮⁤⬢灸≽晵湣瑩潮⁢漨愩筶慲⁢㵣⹣牥慴故汥浥湴⠢摩瘢⤻扨⹡灰敮摃桩汤⡢⤬戮楮湥版呍䰽愮潵瑥版呍䰻牥瑵牮⁢⹦楲獴䍨楬摽晵湣瑩潮⁢渨愩...
Server response begins with 2 "strange" characters before the DOCTYPE declaration (U+02C7 and U+02DB)

Categories

Resources