How do you move a DIV relative to where it is using JavaScript?

Posted on 2014-02-22
Last Modified: 2014-02-22
I have a DIV element and I'd like to move it up by 90 pixels relevant to where it is.  How can this be achieved?

Here's an example of what I want:
When you hover over the game systems area (above the search box), the game system area gets bigger but I'd like for it to also move up by 90 pixels so that when it does get bigger, it only blocks out the stuff above it rather than the stuff below it.

Here's the javascript code I'm currently working with

Open in new window

Question by:davideo7
LVL 38

Accepted Solution

Tom Beck earned 500 total points
ID: 39879195
You can try this however there are numerous validation errors on the page and using inline javascript like this screams trouble to me.

Starting at line 381 of your markup, make the changes in bold.

<table cellspacing="0" cellpadding="0" style="text-align:left;position:relative">
                        <div style="margin: 0px -487px 0px 0px; padding: 0px; border-bottom-style: solid; border-bottom-width: 1px; width: 974px; height: 74px; overflow-y: scroll; overflow-x: hidden; display: inline-block; position: absolute; right: 50%; top: 0; z-index: 2; background-color: transparent;"
document.getElementById('allSystems').style.backgroundColor='transparent';" id="allSystems">


B.T.W., it's not necessary to find the element by Id like document.getElementById('allSystems') when you are already inside the element you intend to modify with javascript. Just use "this".

LVL 52

Expert Comment

by:Julian Hansen
ID: 39879749
Markup is in a bit of a mess. Using tables for layout is also adding to your problems.

If you did a standard <div> layout you could do everything you need with CSS.

First clear all the validation errors - and then consider moving away from your table layout.

Author Closing Comment

ID: 39879794
That worked perfectly!  And thanks for the tips.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form with Modals 16 44
Bootstrap on PLNKR 3 14
how can i remove string values 2 16
How can i get the length? 7 17
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Find out what you should include to make the best professional email signature for your organization.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

15 Experts available now in Live!

Get 1:1 Help Now