Web Design Forums

Javascript, AJAX, and JSON

Having problems with Javascript? Need help picking a library? Post your questions here.

javascript, div's



Site of the Month Nominations
ENTER YOUR SITE NOW!

Reply
 
LinkBack Thread Tools
Old October 31 '03, 09:44 AM (#1)
sopiaz57 is offline
WDF Member
 
sopiaz57's Avatar
 
Join Date: September 2003
Posts: 41
sopiaz57
javascript, div's

Hey guys, i have an easy one here.

2 divs, one visible one hidden. the ID for one div is "div1", the ID for the other div is "div2"


here's my function......to be executed on roll over..


function div_swap()
{
document.div1.visibility="hidden";
document.div2.visibility="visible"
}

whats missing, i know im close.
thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 31 '03, 10:13 AM (#2)
JR is offline
JR
Moderator
 
JR's Avatar
 
Join Date: November 2002
Location: UK
Posts: 4,355
JR is on a distinguished road
Firstly, make sure that it is actually an id and not a name attribute in the div tags.

Then use this...
Code:
function div_swap()
{
document.getElementById('div1').style.visibility = "hidden";
document.getElementById('div2').style.visibility = "visible";
}
However, that is not cross-browser compatible so use...
Code:
function div_swap()
{
document.getElementById('div1').style.top = "-2000px";
document.getElementById('div1').style.left = "-2000px";
document.getElementById('div2').style.top = "0px";
document.getElementById('div2').style.left = "0px";
}
Change the px values depending on where the div is positioned. I think you must also use css positioning as a style for the JavaScript to work, IIRC.

Last edited by JR; October 31 '03 at 11:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 31 '03, 10:24 AM (#3)
sopiaz57 is offline
WDF Member
 
sopiaz57's Avatar
 
Join Date: September 2003
Posts: 41
sopiaz57
thanks, i had something to that degree but yours woked.

Here's the problem now, The one div when i mousover is below the hidden div, can i get around this by using a z-index? or do i have to use positioning??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 31 '03, 11:28 AM (#4)
JR is offline
JR
Moderator
 
JR's Avatar
 
Join Date: November 2002
Location: UK
Posts: 4,355
JR is on a distinguished road
You will have to use positioning. What are the divs for?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 31 '03, 11:43 AM (#5)
sopiaz57 is offline
WDF Member
 
sopiaz57's Avatar
 
Join Date: September 2003
Posts: 41
sopiaz57
the one div holds a flash movie, the other is a pic, then are being swapped and should reside in the same location.

I cant get css positioning to work at all, it's pretty wierd.

heres my <style>

#div1
{

visibility:visible;
left:388px;
top:355px;

}


#div2
{

visibility:hidden;
left:388px;
top:355px;

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 31 '03, 11:46 AM (#6)
JR is offline
JR
Moderator
 
JR's Avatar
 
Join Date: November 2002
Location: UK
Posts: 4,355
JR is on a distinguished road
You will need "position: absolute;" and have one of them placed off the page.

so...

Code:
#div1
{

position: absolute;
left:388px;
top:355px;

}


#div2
{

position: absolute;
left:-2000px;
top:-2000px;

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » Javascript, AJAX, and JSON

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
User Infomation
Your Avatar

Site Of The Month

Ticket Cake
Ticket Cake

Ticket Cake is a drupal based event ticketing platform. It features that ability to browse events and share them.

Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 10:13 AM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163