[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

placing a div exactly div below a td

Posted on 2010-09-01
5
Medium Priority
?
492 Views
Last Modified: 2013-11-19
I have an image inside a td. On mouse hovering the image, another div should show exactly below the td. It should not push the contents of the page down, instead just open it on op of the exisitng page contents. Please help me how I can position the div so that it is displayed excatly below the td. Thanks

I have attcahed the html and javascript that I have.
function HideCart(id) 
        {
            if (id.length < 1) 
            {
                return; 
            }
            document.getElementById(id).style.display = "none";
        }

        function ShowCart(id) 
        {
            
            if (id.length < 1) {
                return; 
            }
            document.getElementById(id).style.display = "block";
        }

<img src="Assets/Images/Master/shoppingcart.jpg" 
                                     style="height: 34px; width: 60px; " alt=' '  onmouseover="ShowCart('divCart')" onmouseout="HideCart('divCart');" />
                                <div    id="divCart"    style="display:none;       position:absolute;       border-style: solid; background-color: #E5E5E5; height: 4px;      padding: 5px;" class="search">
 ctent here</div>

Open in new window

0
Comment
Question by:TrialUser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 1000 total points
ID: 33576314

<div    id="divCart"    style="display:none; position:relative; .....

function ShowCart(id) {
      var ele = document.getElementById(id);
      var ele2 = document.getElementById("tdShoppingCart");
      ele.style.Top = ele2.style.top + ele2.style.height;
      ele.style.display = "block";                        
}
0
 
LVL 19

Assisted Solution

by:Bardobrave
Bardobrave earned 500 total points
ID: 33576319
You can try to retrieve the top and left positions of the TD on hover, and positioning your div dinamically on same left and a top equal to the td's + it's height.

I'm not sure if this will work well, as every browser has it's own conception of positioning.

I'd rather prefer to seek a solution base on design. Maybe you should allow enough space in your td below the image to fit there your div, and show or hide it on hover event.

0
 

Author Comment

by:TrialUser
ID: 33577023
junges:
I get the ele2 as null. I even tried to pass the element id to the javascript but still it shows null.

Please help
"ShowCart('tdShoppingCart','divCart');"

  function ShowCart(idTD,id)
        {

            if (id.length < 1)
            {
                return;
            }
            var objTD = document.getElementById(idTD);
            alert(objTD);
            var objCart = document.getElementById(id);
            alert(objCart);
            objCart.Style.Display = "block";
            objCart.style.top = objTD.style.top + objTD.style.height;
 
                    }
0
 
LVL 14

Assisted Solution

by:Daniel Junges
Daniel Junges earned 1000 total points
ID: 33579025
hi TrialUser,

its null because you <td> has the argument runat="server", can you remove it ?
0
 
LVL 22

Assisted Solution

by:kadaba
kadaba earned 500 total points
ID: 33579276
you might try it this way....
using jquery would make the code nice

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Sample</title>
<style type="text/css">
.hiddenDiv
{
	position:absolute;
	border:solid 1px #aaaaaa;
	background-color:#FFEE00;
	width:150px;
	height:150px;
}
.oddTr td{
	background-color:#E1E1E1;
}
.evenTr td{
	background-color:#FFFFFF;
}
</style>
 
<script type="text/javascript">

function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
 
function ShowCart(parent,cartId,content)
{
	var divCart =  $(cartId);
	divCart.innerHTML = content;
	
	var pos = findPos(parent);
	divCart.style.left = (pos[0] + 20) + "px";
	divCart.style.top = (pos[1] + 20) + "px";
	divCart.style.display="block";
}
 
function $(id){
	return document.getElementById(id);
} 

function HideCart(cartId)
{
	var divCart = $(cartId);
	divCart.style.display = "none";
}
</script>
</head>
<body>
<div class="hiddenDiv" id="divCart" style="display:none;">
</div>
<table border="1" width="300px">
	<tr class="oddTr">
		<td>
			No action
		</td>
		<td style="cursor:pointer;" onmouseover="ShowCart(this,'divCart','Lorem ipsum dolor sit amet');" onmouseout="HideCart('divCart')">
			Mouse over me
		</td>
	</tr>
	<tr class="evenTr">
		<td style="cursor:pointer;" onmouseover="ShowCart(this,'divCart','consectetur adipisicing elit, sed do eiusmod ');" onmouseout="HideCart('divCart')">
			Mouse over me
		</td>
		<td>
			No action
		</td>
	</tr>
	<tr class="oddTr">
		<td>
			No action
		</td>
		<td style="cursor:pointer;" onmouseover="ShowCart(this,'divCart','Lorem ipsum dolor sit amet');" onmouseout="HideCart('divCart')">
			Mouse over me
		</td>
	</tr>
	<tr class="evenTr"> 
		<td style="cursor:pointer;" onmouseover="ShowCart(this,'divCart','consectetur adipisicing elit, sed do eiusmod ');" onmouseout="HideCart('divCart')">
			Mouse over me
		</td>
		<td>
			No action
		</td>
	</tr>
</table> 
</body>
</html>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

650 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