Jump to:

23380 Posts in 18311 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » JQuery conflict: unrecognized expression [ SOLVED ]

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 3446 Views
  • xpyx
    Avatar
    Community Member
    5 Posts

    JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    I have a page which is breaking on this function:

                $(options.navigation).click(function() {
                   panel = $($(this).attr('href'));
                   $(window)._scrollable().stop();
                   $.scrollTo(panel, {
                      duration: 500,
                      easing: 'swing'
                   });

    HTML: <a href="#panel1" class="navigation" title="Panel 1">1</a>

    It gives me "Syntax error, unrecognized expression: /" clicking on any navigation item, from the line "panel = $($(this).attr('href'));"

    If I have the exact same HTML page outside of Silverstripe it works perfectly.

    If I copy the file to say, http://localhost/dev.html and run this inside SilverStripe it's also fine.

    But if I run it at http://localhost/dev/ it gives me the Syntax error again. Is is something to do with mod_rewrite? The script even works fine when I'm not running it via a server (just directly in the browser).

    Any theories about what's going on here? I've been stuck on this bug for a couple of hours now, would be wonderful to know if there is a fix.

  • danzzz
    Avatar
    Community Member
    175 Posts

    Re: JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    try this in init() of Page_Controller

    Requirements::set_write_js_to_body(false);

  • xpyx
    Avatar
    Community Member
    5 Posts

    Re: JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    Thanks, no luck I'm afraid. I've made sure all the javascript includes are not minified. Would love any other input.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    SilverStripe is rewriting the link so that it includes the current URL so that the anchor link actually works. You can usually get around this by using single quotes around the href attribute instead of double quotes.

  • xpyx
    Avatar
    Community Member
    5 Posts

    Re: JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    Thank, I have single quotes: $($(this).attr('href'));

    Any other thoughts?

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    Not in the JavaScript, in the template.

  • xpyx
    Avatar
    Community Member
    5 Posts

    Re: JQuery conflict: unrecognized expression [ SOLVED ] Link to this post

    Awesome, fixed! Thank you so much.

    Changed:<a href="#panel1" class="navigation" title="Panel 1">1</a>

    To: <a href='#panel1' class='navigation' title='Panel 1'>1</a>

    Thanks, that's really great to know.

    3446 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.