Solved

Change element depending on current page using jQuery

Posted on 2013-01-06
5
291 Views
Last Modified: 2013-01-07
Hi guys,

I am trying to figure out a way to change the position of a css element depending on the page it is being viewed using jQuery. I must stress that I am very new to jQuery and would like to know how I can manipulate the DOM for my site.

I need something like this:

if element is on homepage {position:relative} else {position:fixed};

I really not sure how to do this and would be grateful for some assistance please...
0
Comment
Question by:rafique12
  • 3
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
Comment Utility
Why would you not just have two classes in your stylesheet; one with position:absolute, and one with position:relative?  Then on the server you generate the element with the class it needs.  You know what page you are sending, so you do it when you generate the page. instead of screwing around with client side scripting.

Cd&
0
 

Author Comment

by:rafique12
Comment Utility
You have a point, a very good point!

I was trying to avoid duplicating the template file for shopping cart sidebar (Magento). I currently have it showing on the product view page with position relative. I also have it showing on the checkout page where I would like it to be fixed so its always visible when scrolling down the page....
0
 

Author Comment

by:rafique12
Comment Utility
Its only fair. Thanks for the nudge!
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Why the C if my response did not help then just have the Q deleted and indicate you need something additional.  It is really quite insulting that I am the only one to respond to your question and you throw the lowest possible grade at me, without any indication of a reason for it.

Cd&
0
 

Author Comment

by:rafique12
Comment Utility
You shouldn't be insulted, its an average answer to a question that had asked for something more specific. I preferred to award you the points instead of deleting the question as I thought that would have been an insult... Seems I was damned if I did and damned because I didn't.

Is there a way to change the grade?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now