473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Targetting specific pages in an app with jQuery

97 64KB
I need help figuring out how to find only certain pages in my app. I'm trying to remove two elements from the page, but only for three pages of my app, and only for desktop devices.

This is the little function I made so far:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $(window).load(function() {
  3.   // Check media queries
  4.     if($(window).width() >= 769) {
  5.   // Get pathname of page
  6.     var page = window.location.pathname;
  7.   // If pathname matches any of these
  8.     if(page = 'Page2','Page3','Page4'){
  9.   // Remove two elements
  10.     $('#element1').css('display','none');
  11.     $('#element2').css('display','none');
  12.     }
  13.     else{
  14.       $('#element1').css('display','block');
  15.       $('#element2').css('display','block');
  16.     }
  17.   }
  18. });
  19.  
The first line is fine - the elements are removed for desktop devices, but are still displayed on mobile ones.

It's the second and third lines that are the problem - the elements are removed from all pages of the app, not just the three pages that are set up.

Also, not sure if the else statement is needed. Please let me know if it's redundant.
Nov 3 '15 #1
0 6663

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Rob Tweed | last post by:
Two inter-related questions: If I'm in PHP page a.php, and I want to switch control to page b.php, the only mechanism I've come across is to use header('Location: someURL") ; This has two...
19
by: Joshua Beall | last post by:
Hi All, I would like to setup my site so that when a page is request that does not exist, transfer is instead passed to a certain page that I specify. For instance, if the user requests...
1
by: ABC | last post by:
I want to check the user roles for allow/deny access each pages. I know it is possible to add check code on each page. But is very spent time. Is there any configuration (web config) parameters...
2
by: cemlouis | last post by:
Hi, I want to show some specific pages to people that comes to my site from specific urls, I know the variable $_SERVER will be used but how? For ex if the visitor comes from a site that is...
3
by: singleclick | last post by:
Hi all, i would like to generate the login page for some specific pages. What i have to do if the Authentication mode is Windows and Authentication mode is Forms. Thanks in advance for replying.
1
by: Big Moxy | last post by:
This plugin can be downloaded from http://www.phpletter.com/DOWNLOAD/. I want to add 2 fields to the sample form but do not know how. The variable s.fileElementId in the function ajaxFileUpload...
1
by: powermetal114 | last post by:
Hi, following Peoblem: I have a PDF-file. I woud like to insert a field, code or whatever between two Pages in MS-Word as a printer-instruction. The idea is to print the whole Word Ducument then...
1
by: viana2020 | last post by:
hey,how can i direct users to their specific pages on login?and to make users only view their entries and not anyone else's. below is my html code which is loggin in but to a common page. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.