JavaScript - Set Multiple Div Height By Container
Hi Folks,
Hope someone can help. I want to do this with js and not with any html/css tables, image fills or whatever other trick, but I don't know how... Say I have multiple DIV containers below each other, which contain multiple DIV boxes floating next to each other. None of the DIV elements have a fixed height: Code: <div id="container1"> <div id="box1">some text</div> <div id="box2">some double more text</div> <div id="box3">some other text</div> </div> <div id="container2"> <div id="box4">some double more text</div> <div id="box5">some more text</div> <div id="box6">some other text</div> </div> I want for each container (separately) to have the contained box divs to fit the biggest one in height. For example, in container1, if box2 contains more text than the others, I want box1 and box3 height to fit box2. And in container2, if box4 has more text than the others, I want box5 and box6 height to fit box4, etc. In my dreamworld, the solution would be flexible and fully automated, which means, it would look for all container divs of class x or Id x and apply the same rule to all child divs. Hope it's clear enough ;o) I have heard of jquery "equalheights" plugin but I don't think it can do that ? or then I misunderstood something. Could I be using some "get element by class" function and then apply a style.height to the divs? TIA for any suggestion Similar Tutorialsi want to set the second container's height according to the first container's.but how to achieve the height of the container dynamically. thank you! Hi, I need to re-size a div to be 100% of the browser but taking into account the height of an existing header div. Currently it works but it doesn't factor the height of the above header div, and therefore scrolls off the page (the height of the header div) I need to manipulate ( subtract the height value of the header) in the javascript somehow. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript"> function SetHeightOfDiv(){ var theDiv = document.getElementById('content'); theDiv.style.height = BrowserHeight()+"px"; } function BrowserHeight() { var theHeight; if (window.innerHeight) { theHeight = window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { theHeight = document.documentElement.clientHeight; } else if (document.body) { theHeight = document.body.clientHeight; } return theHeight; } </script> </head> <body style="height:100%; background-color:blue; margin:0; padding:0; color:#ffffff; font-size:15px; text-align:center; font-family:monospace,arial" onload="SetHeightOfDiv()"> <div id="wrapper" style="height:100%; width:900px; background-color:yellow; margin-left:auto; margin-right:auto; overflow:hidden"> <div id="header" style="margin-top:0px; height:130px; width:890px; margin-left:5px; background-color:red; position:fixed"> <p>The FIXED HEADER</p> </div> <div id="content" style="margin-top:132px; background-color:grey; width:890px; margin-left:5px"> <p>THE BODY - that extends below the browser window (possibly the height of the header)</p></br> <p>So how do we manipulate the Javascript to 'Subtract' the height of the HEADER?</p></br> <p style="text-align:left; padding-left:10px"> function SetHeightOfDiv(){ <br> var theDiv = document.getElementById('content');<br> theDiv.style.height = BrowserHeight()+"px";<br> }<br> </br> function BrowserHeight() {<br> var theHeight;<br> if (window.innerHeight) {<br> theHeight = window.innerHeight;<br> }<br> else if (document.documentElement && document.documentElement.clientHeight) {<br> theHeight = document.documentElement.clientHeight;<br> }<br> else if (document.body) {<br> theHeight = document.body.clientHeight;<br> }<br> return theHeight;<br> }</p> </div> </div> <!--end of wrapper--> </body> </html> Thanks Hello, I'm a beginner to Javascript and I have a problem. My idea is to move the container to the right of the page when the user has a widescreen. This is what I came up with: Code: width = 1; height = 1; var container = document.getElementById('container'); if (typeof (window.innerWidth) == 'number') { width = window.innerWidth; height = window.innerHeight; } else { width = screen.width; height = screen.height; } if ((width / height) > 1.5) { container.style.right = 0; container.style.position = 'absolute'; } Everything works fine, except the style part. Can anybody help me?? Hi, I hope someone can help me. I'll be honest and say I don't know much about javascript, but am fairly comfortable in html. I am building a website that will have multiple image swaps on multiple pages. I am building this in wordpress, and I'm guessing that means my approach will be different than if I wasn't using wordpress. Here's how one page would work: There are 10 images shown. 1,2,3,4,5,6,7,8,9,10. When number 1 is clicked on, I want a new image - 1a. When 2 is clicked on, 2a. So there are 20 different images in all on a given page. Also, I want the user to be able to click on the image again to restore the original image. I would prefer onclick to onmouseover. There will be literally dozens of pages like this on the site, managed by wordpress, so hundreds of images to swap. Basically the first image is a question - the second image is the answer. Is this possible? I have a container that has <li> items in it and in order to expand them you hit the + sign to smoothly expand the content under that header. My problem is that I want the header and the + to be on the same line and to not be appended to the <li> items when they are expanded. Right now the read more button(expand button) ends up at the bottom when it is clicked because of the list items expanding. Here is my js for that section, and the css for the read more button. Code: // auto-add-in 'read more' hooks after 4 bullet points $("#att_container ul").each(function() { var elem = $(this); // break up list into separate lists, more than 4 is toggle_container if ( elem.children("li").length > 0 ) { elem.after('<ul class="toggle_container">'); // add hidden container after current element var hiddenContainer = elem.next(".toggle_container"); // save a reference to it elem.children("li").slice(0).appendTo(hiddenContainer); // move the children past the limit hiddenContainer.after('<p class="trigger"><a href="#"> </a></p>'); // read more button } }); //Hide (Collapse) the toggle containers on load $(".toggle_container").hide(); //Switch the "Open" and "Close" state per click $("p.trigger").toggle(function(){ $(this).addClass("active"); }, function () { $(this).removeClass("active"); }); //Slide up and down on click $("p.trigger").click(function(){ $(this).prev(".toggle_container").slideToggle("slow"); }); // Expand and Collapse All $(".expand").click(function(){ $("p.trigger").addClass("active").prev(".toggle_container").slideDown("slow"); }); $(".collapse").click(function(){ $("p.trigger").removeClass("active").prev(".toggle_container").slideUp("slow"); }); }); Here is the css for the read more button Code: #att_container p.trigger a { display:block; float:right; width: 76px; height: 19px; margin: 0; padding: 0; background: url(../images/readmore_att.jpg) top left no-repeat; } #att_container p.active a { background: url(../images/readmore_att.jpg) bottom left no-repeat; } Hey guys. I've been trying to figure this out now for the past 9 hours and I have no idea what I'm doing...lol Ok, I have images inside of a container that is inside of an iframe. When I click on an image, content underneath is revealed by sliding everything underneath it down. The problem I have is that when it slides the content down, all the other images and content are cut off. I want it that when the content extends past the height of the div#container, it autoresizes, if that's possible. But I don't wanna use the iframe scrollbar. Only the parent scrollbar. Here's a link for the entire code of the Website. Open up index.html, click on Salvation and click on one or two of the images, and you'll see what I'm talking about. The salvation.html is the source for the iframe. http://www.mediafire.com/?zqzym4iniyd Thanks so much for your help! Hi all Ive basically 3 php scripts: -one that writes an xml file from a directory of image files -one that creates a thumbnail from a jpeg file resizes it and puts a little drop shadow on the thumbnail -one that reads the xml file and outputs the html code so all is good a little old school, but it works, I get a page of thumbnails in whatever form I want with links. Ive attached a lightbox script I found to open the thumbnails and thats ok. What I would like to do is target the images to a container inside a div tag using jquery, maybe even fade the image in something fancy. but Id be happy with the basics. Just click on the thumbnail show it in the adjacent container. (dont have a container yet thats what i need some help with with) I'm doing my best going through various tutorials and the chm file learning as I go here is the test page that outputs the thumbnails: http://www.eagleview.ca/newsite/cont...om=0&pageto=12 any help is appreciated william Greetings, I am looking for either a JavaScript or Coldfusion solution to the following problem. First, there are over 60 million product photos so downloading and resizing the photos using Coldfusion would be very tedious. I would like the display an image within a 100 x 100 pixel container. If the height or width of the image is great than 100 pixels, the image should reduce in size to fit within the 100 x 100 pixel container. I want to avoid pixelation of the images as much as possible. All images are external and not on the local server so I only have an image URL. I would like to hide all images until they are resized appropriately. Does anybody know of a piece of javascript code that can do something similar to this? Sincerely, Travis Walters Hola, I have a problem where I have a number of random set of elements that have a fixed rule for class name. I want to move them to a container element according to this class name. So for example the site generates Code: <p class="dog-1"></p> <p class="dog-2"></p> <p class="cat-1"></p> <p class="dog-3"></p> My output would be ideally Code: <div class="dog"> <p class="dog-1"></p> <p class="dog-2"></p> <p class="dog-3"></p> </div> <div class="cat"> <p class="cat-1"></p> </div> When searching for a solution, all I could find was simple ordering of elements according to class... Thanks I am doing a project and I have a problem. I have retrieved data from a json file using ajax and the xmlhttprequest, but I am not able to put the content I retrieve into the dojo content pane. The content pane is inside a border container. I have tried the following, but it does not work. The HTMLPage4.html has the json data inside. please help me really urgent to me!!!!!!!as soon as possible Code: function getInfoContent(graphic) { function ajaxRequests() { var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) for (var i = 0; i < activexmodes.length; i++) { try { return new ActiveXObject(activexmodes[i]) } catch (e) { //suppress error } } } else if (window.XMLHttpRequest) // if Mozilla, Safari etc return new XMLHttpRequest() else return false } var mygetrequests = new ajaxRequests() mygetrequests.onreadystatechange = function() { if (mygetrequests.readyState == 4) { if (mygetrequests.status == 200 || window.location.href.indexOf("http") == -1) { var bookss = eval("(" + mygetrequests.responseText + ")") //retrieve result as an JavaScript object var rssent = bookss.infos.info for (var i = 0; i < rssent.length; i++) { // alert(mygetrequests.responseText); var placeImg = "" var txt = "" // placeImg += rssent[i].descImg txt += rssent[i].desc var shorttxt = "" shorttxt += txt.substring(0, 30); var bc = new dijit.layout.BorderContainer({ style: "font-size: 11pt; height: 574px; width:739px; border:0px;" }); var c1 = new dijit.layout.ContentPane({ region: "top", style: "height: 11.5%; width: 100%; color: black; background-color: transparent; border:0px;", content: "<table><div id = \"mydiv\">" + shorttxt + "<font color = '#0000FF' size = '1'><a onclick='showmore();'><u> More...</u></a></div></td></table>" }); bc.addChild(c1); } } else { alert("An error has occured making the request") } } return bc.domNode; } mygetrequests.open("GET", "HTMLPage4.htm", true) mygetrequests.send(null) } The bit of code in bold in the code below is giving me this error in IE: Error: Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; Tablet PC 2.0; InfoPath.2; OfficeLiveConnector.1.4; .NET CLR 3.0.30729; OfficeLivePatch.1.3; MSN OptimizedIE8;ENGB) Timestamp: Tue, 16 Mar 2010 15:07:11 UTC Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917) Line: 0 Char: 0 Code: 0 URI: http://www.mateinastate.co.uk/users/mateinastate Code: Code: if(document.getElementById('msn1').innerHTML=="") { document.getElementById('msn1').style.display='none'; } if(document.getElementById('yahoo1').innerHTML=="") { document.getElementById('yahoo1').style.display='none'; } if(document.getElementById('skype1').innerHTML=="") { document.getElementById('skype1').style.display='none'; } if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,18)=='<a href="http://">') { document.getElementById('facebook1').style.display='none'; } else if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,11)=='<a href="">') { document.getElementById('facebook1').style.display='none'; } else { document.getElementById('fbook-add').innerHTML='Facebook Profile'; } What it's saying isn't actually true (I don't think)... this is how the section is laid out: Code: <div id="submenu1" class="anylinkcss"> <ul> <li class="contact-pm"><a href="/index.php?do=pm&act=new&to=$RateViewProfileUserName$&returnurl=$ReturnURL$">PM me</a></li> <li class="contact-email"><a href="/index.php?do=email&id=$RateViewProfileUserId$">E-mail me</a></li> <li class="contact-msn" id="msn1">$RateViewProfileUser-profile_msn$</li> <li class="contact-yahoo" id="yahoo1">$RateViewProfileUser-profile_yahoo$</li> <li class="contact-skype" id="skype1">$RateViewProfileUser-profile_skype$</li> <li class="contact-facebook" id="facebook1"><a href="$RateViewProfileUser-profile_facebook$"><span id="fbook-add"></span></a></li> </ul> </div> <script type="text/javascript" src="/html_1/js/contact-information.js"></script> Does anyone know why this might error in just IE? Can DIV located in the MasterPage be resized depending on the screen resolution? <tr style="vertical-align: top;"><td> <div id="mainArea"> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server" /> </div></td></tr> I've tried unsuccessfully - var height = screen.height; var area1 = document.getElementById('ctl00_mainArea'); if (height == 1024) { area1.setAttribute("height", "700px"); } else if (height == 864) { area1.setAttribute("height", "540px"); } Also tried area1.style.height = 700 + "px"; (no luck as well) hi guys.. i have a problem.. first i have a about_us.php page.. which inside the about_us page i include right banner page.. using php include.. and this right banner page height must be the same height as the about_us page.. so i need using js to get the actually about_us page height and send to right_banner page so i can process it.. my logic are get the div height from about_us page.. send it to right_banner page.. and using php to process it,so the right banner height can be similar to about_us page when about_us page open by user.. about_us.php i using div input all the stuff Code: <div class="mainarticel">text goes here </div> and mainarticle css i put in outside css.. called style.css nb:mainarticle height i using auto; and in right_banner page i using Code: function getHeight (id) { var gh = document.getElementById(id).offsetHeight; alert (gh);} but this cannot get the div from another file.. so how can i get the div height from another file? I just placed this div named iframe_container in a table cell. There's an iframe and another div inside of it and when I went to fine tune the alignment I discovered I could change the width of the div but not the height I can set it to 200 or 1000, it doesn't make the slightest difference. It seems to be clinging to the outside of the iframe. I can make it bigger by inserting breaks after the iframe but then the compass_rose div loses its absolute position for some reason I searched the page for height tags that might be interfering with this but I've turned up squat. I took the height specs off the table but still no effect. Can anyone spot the problem? <td style="width: 800px; height: 700px" valign="top" class="style3" align="left"> <div id="iframe_container" style="width:1000px; height=700; position: relative; overflow-x:auto; overflow-y:hidden"> <div id="compass_rose" style="top: 5px; left: 1200px; position: absolute; z-index: 2; visibility:visible;"><img alt="Compass Rose" src="compass_rose_animated2.gif" width="80" height="80" /></div> <iframe id="viewer" width="1600" height="635" src="front_page2.jpg" marginwidth="1" marginheight="1" name="viewer"></iframe> </div> </td> </tr> </table> I'm trying to make height of my leftNav div the same height as the mainContent div. currently I have Code: jQ(document).ready(function() { //even the left bar and the main Content jQ('#leftNav').height( jQ('#mainContent').innerHeight() ); }); This only works on some pages, and not on others. for example it works here http://nminvestigates.townsendwebdd.com/index.php but not here http://nminvestigates.townsendwebdd...._prepared2.php Help please This works: Code: <div id="oDiv" style="width:300;height:100;background-color:#000000;"></div> <a href="#" onclick="getHght('exp');">Expand</a> <a href="#" onclick="getHght('con');">Contract</a> <script type="text/javascript"> <!-- function getHght(act){ var doc = document.getElementById("oDiv"); if (act == "exp"){ doc.style.height = 300 ; } else if (act == "con"){ doc.style.height = 100 ; } } //--> </script> This is exhibits the desired functionality, but it doesn't work: Code: <div id="oDiv" style="width:300;height:100;background-color:#000000;"></div> <a href="#" onclick="getHght('exp');">Expand</a> <a href="#" onclick="getHght('con');">Contract</a> <script type="text/javascript"> <!-- function getHght(act){ var doc = document.getElementById("oDiv"); if (act == "exp"){ doc.style.height += 30 ; } else if (act == "con"){ doc.style.height -= 30 ; } } //--> </script> IE give an "invalid argument" error. No error in FF. I had the same [failed] result using .getAttribute(), and .setAttribute(). How should I approach this? -james Hello... Just curious on what I am doing wrong: I want to get the pixelHeight of a div called content and assign it to a variable. Then I want to use that variable as the css top position property for another div. I'm new to Javascript, but am learning it. Right now I am just having trouble assigning the variable. I get 'undefined' when I try to output the variable to the browser. Here's the code : Code: <script language="javascript"> var divh = document.getElementById('top').style.pixelHeight; </script> </head> <body> <!-- output divh --> <script language="javascript"> document.write(divh); </script> this gives me undefined in my browser What am I doing wrong?? Thanks Kevin It appears Lightbox has a bug in IE when the screen height exceeds 65,505 pixels. I have created two test pages for you to see. One that shows the bug and another that shows it working. The problem seems to be ONLY with Internet Explorer (of any version). In the following test htm pages click the "Click Here" link at the top left corner. You will see a lightbox pop up on screen. The issue is related to the opacity level. When the screen height is <= 65,505 pixels the opacity works fine for IE. But if the height >=65,506 it fails. It is not an IE bug because i tried using filter: alpha(opacity) and it works fine. It seems to be a lightbox bug. Test 1: Opacity Works because Height of Screen is 65,505 pixels: http://fatcatdaily.com/test-works.htm Test 2: Opacity Fails because Height of Screen is 65,506 pixels: http://fatcatdaily.com/test-fail.htm NOTE: You MUST be using Internet Explorer to see the BUG |