Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:06:07+00:00 2026-05-28T07:06:07+00:00

I have some JQuery written which is intended so when a user navigates to

  • 0

I have some JQuery written which is intended so when a user navigates to ‘page/2/’ in WordPress, an image appears in the sidebar. It’s CSS is set to display:none; initially, then I have JQuery change it to display:block; if that URL string is present. The code I wrote has it backwards… so it does this to every page BUT ‘/page/2/’.

$(document).ready(function() {

var url = window.location.pathname;
if(url.indexOf('/page/2/')){
    $('.sidebarimage').css("display","block");
}});

I always thought if there was no condition set in an If statement, it treats it as true, and anything else as false. Should I put a = 1 or something here? What am I missing?

Many thanks SO

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:06:07+00:00Added an answer on May 28, 2026 at 7:06 am

    The if block will be entered if the value of the condition is convertible to true. In Javascript any non-zero number is true and the return value of indexOf when the string is not found is -1. Hence any time it’s not there it gives back -1 which is seen as true and the if block is entered.

    Change the conditional to be explicit to what you’re looking for

    if (url.indexOf('/page/2/') !== -1) {
      $('.sidebarimage').css("display","block");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jquery/php interaction set up on a page. It submits some data
I have written some Javascript (specifically a jQuery plugin) in which I replace the
I have written some jQuery ajax code where I am sending a request to
I have some jquery code which I am trying to translate to YUI. I
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
Hello there i have written some code in jquery to add new input type
I have a fairly complex object which has some C# code written to render
I have a some html being generated by JQuery on a Share Point page.
I have some simple jQuery written to sort some elements based on a numerical
So I've got some scripts I've written which set up a Google map on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.