JQuery selector problem - 'Syntax error, unrecognized expression' fix
I just spent a little time wrestling with an annoying JQuery error when trying to select a form element by name.
I was using the following code to simply grab the contents of a hidden field named 'required':
I got this syntax from a quick google search and found it referenced on a number of web guides about JQuery.
However, when I used it I got the following error in Firefox:
Well after some head scratching and then some more searching I found the answer. The @ syntax is no longer supported in JQuery 1.3+.
So the simple fix is to just remove the @ and it'll work as expected:
Hopefully this will help someone who, like me, hit's Google when looking for a quick fix to a problem.. :)







Thanks for your comment and glad you were able to find the answer to this issue quickly. I like being able to hit Google when I get an error and get the answer straight away. No hassle and then we can get right back to the creative part of our job. :)
Thanks too. But, we have to change 493 errors regarding '@'. Are you sure, there's nothing will happen?
The @name syntax is certainly not supported anymore so replacing '@name' for 'name' should do the trick.
My advise is to first take a full copy of the site and then do the global search and replace. Test the site and if there are any problems roll back. Do it locally first if you can.
Thanks!
~Doug
Excellent. Glad to know it was able to help you out quickly. Nothing better than finding the answer to a creativity destroying problem at the number slot on good old Google.
Thanks for taking the time to comment.
Nice to know this is helping people. The quicker this kind of problem is solved the better in this game.
Hey no probs - glad I could help. Thanks for posting.
http://docs.jquery.com/Selectors
Still, seems like they should have a breaking change like that in blinking red all over their site =)
the first search Result in search Engine show me this Answer :)
".nowrap destFolder"
I keep getting the error - Uncaught Exception: Syntax error, unrecognized expression: 'destFolder'
This exception happens for the second class name, and is thrown from the Sizzle.filter function on line 1579.
I would definitely appreciate any help or information regarding if there was a change in syntax for class names. Thank you
Amar
Sorry for the delay in replying.
Did you fix this issue? I'm not quite sure what might be causing it but I don't think it's related to the @ problem.
I would be interested to hear what the problem was though if you resolved it.
It appears that you have a miss-placed "." the . is not allowed at the beginning of class names in html, only neccassary in CSS.
On another note, you may get this error even if you have not recently upgraded or do not use the @ sign.
I am recieving this error with this line of code pop = $("#" + sID + "_popup").length;
Apparantly somewhere I am setting this to an object, so when I go to use it here it is not a string; I am not sure where or why.. Just an FYI on this error
Had an issue where I was using data returned from a form (using mysql_insert_id() in php) to call an ajax function on success.
As far as I could tell it was just returning '123' which was an ID to be used in the jquery load() function (e.g. mypage?id=123)
Code:
var theID = $.trim(data);
$('#container').load('mypage.php?id='+theID);
The problem I had was that when the initial page was run (to insert a value and then return its ID via "echo mysql_insert_id") it didn't just echo '123'.
Because of the way I had placed the code what it was actually returning was "123 </body></html>" which, according to the code above, resulted in:
.load('mypage.php?id='+'123</body></html>'.
Moving my returned data to a better location removed the issue.
Just spent over an hour fixing this - hope it helps someone else!
$("label[@for="+error_encontrado.id+"]").before("<p class='error'>"+error_encontrado.msg+"</p>");
I just put off the@ and it worked.
Thanks again.
@Toby - great tip there, thanks for that.
if(jQuery("input:radio[name=payment_option[]]:checked").length==0){
str+='Please Select a Payment option\n';
}
but now it gives me error whenever i try to add the square brackets "[]" with the name can any one tell me how should i check this
try this:
$('input:radio[name="payment_option[]"]:checked')... I guess it should do the trick... the issue is the simple and double quotes
wher s is html code getting from ajax response.
In fireFox getting the above error