Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript jquery unrecognized expression:

stefan86

New Coder
Hello all, I have a Syntax error, unrecognized expression. I use a set of links to change to a div on the same page and sent a variable with it.


<a href="?taal=<?PHP echo $taal; ?>#Home">Voorpagina</a>
<a href="?taal=<?PHP echo $taal; ?>#Updates">Updates</a>
<a href="?taal=<?PHP echo $taal; ?>#About">Over mij</a>


$taal is the language the user choose, like NL, EN...

After the user clicks, get this in action:

$('a').click(function (e) { $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 500); });


Everything works but I get the next error in my console:

Uncaught Error: Syntax error, unrecognized expression: ?taal=nl#Home
at Sizzle.error (jquery-3.6.0.js:1681:8)
at Sizzle.tokenize (jquery-3.6.0.js:2381:11)
at Sizzle.select (jquery-3.6.0.js:2842:20)
at Function.Sizzle [as find] (jquery-3.6.0.js:898:9)
at jQuery.fn.init.find (jquery-3.6.0.js:3099:11)
at new jQuery.fn.init (jquery-3.6.0.js:3209:32)
at jQuery (jquery-3.6.0.js:161:10)
at HTMLAnchorElement.<anonymous> (?taal=nl:175:24)
at HTMLAnchorElement.dispatch (jquery-3.6.0.js:5430:27)
at elemData.handle (jquery-3.6.0.js:5234:28)

How can I resolve this error? By the way, if I remove the <?PHP echo $taal; ?> variable in the links above (first code), the error is gone but I need that variable for further navigation.

Thanks in advance.
 
I use a set of links to change to a div on the same page and sent a variable with it.
Changing to a local <div> is fine, but how do you envisage passing a variable with that ? Or rather, how should the div pick that value up ?
Assuming $taal is nl, your PHP lines result in this HTML :

HTML:
<a href="?taal=nl#Home">Voorpagina</a>
<a href="?taal=nl#Updates">Updates</a>
<a href="?taal=nl#About">Over mij</a>

but those are not valid href's. This

HTML:
<a href="#Home?taal=nl">Voorpagina</a>
<a href="#Updates?taal=nl">Updates</a>
<a href="#About?taal=nl">Over mij</a>

would make more sense, but I'm still not sure how the html is supposed to pick up that parameter. Why do you feel the need to pass it anyway ? You can ask PHP for it any time you need it.
 

New Threads

Buy us a coffee!

Back
Top Bottom