Problem with . show()

Asked

Viewed 52 times

0

Basically I have a jQuery code that should show the widgets on a certain page of my website (their property would be #left, #right) only it’s not working and I can’t figure out why. Here’s the code I’m using:

jQuery(document).ready(function(){
    if(location.pathname=='/forum'){
        jQuery('#left,#right').show()
    }
});

I use to show the widgets only on the page and to hide them from the other pages I use this CSS:

#left,#right{display:none}

Could anyone see what is wrong? Thanks in advance.

  • What is returning in Location.pathname when you access the forum page?

  • Only thing that is returning is this: Uncaught Syntaxerror: Unexpected Identifier VM93:1 'webkitIDBObjectStore' is deprecated. Please use 'Idbobjectstore' Instead.

  • Apparently the error is not in your code snippet, maybe some other function is giving error.

  • Fábio, can you debug from the browser console? If there are errors in the console they may be preventing your code from running. Always look for your code, makes it easy to find possible errors. Another tip if you don’t know how to debug from the console is to put an Alert("") before the "jQuery() function. show()", to make sure that you are entering the if.

  • There are two errors as mentioned above: Uncaught Syntaxerror: Unexpected Identifier VM93:1 'webkitIDBObjectStore' is deprecated. Please use 'Idbobjectstore' Instead.

  • These errors are sometimes in another js file and pass beaten. Ideally you debug your code.

  • Fábio, that Uncaught SyntaxError disappeared?

  • Yes Sergio! : D Very strange.

  • Fabio: and it returns if you take window from window.location.pathname?

  • Yes, that’s why I find it very strange.

  • It really doesn’t make sense. location is a global variable, can be accessed with or without window.. Unless there’s another, local, with the same name and in the scope you’re in.

Show 6 more comments

1 answer

1


Change location.pathname for window.location.pathname in your code.

  • It worked! Weird, just because of window.location.pathname lol

  • I gave an Edit in the answer, you can [Edit] and add one more line to explain if you want. I think the problem really wasn’t this :P

  • Zanotta, to ask questions about the question, please use the comments. No problem because the edition of sensei Sergio stuck in the fly... :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.