tags:

views:

298

answers:

1

I have the following DIV's on my page. I am increasing/reducing the width of the LeftDiv (div id="leftc") on mouse over and mouse out

<div id="outerwrap">
          <div id="innerwrap">      
             <div id="centerc">...</div>          

             <div id="rightc" style="font-weight:bold">
          </div>
          <div style="background-color:White;height:10px;top:284px;left:0px"></div>

          <div id="leftc">..</div>
        </div>
       <div id="footer"">...</div>

jQuery logic,

<script type="text/javascript">
    $(document).ready(function() {

        $("#leftc").hover(
            function mouseover() {
                $(this).css({ width: "190px" });
                $("#centerc").css({ "margin-left": "195px" });
            },
            function mouseout() {
                $(this).css({ width: "25px" });
                $("#centerc").css({ "margin-left": "29px" });
            }
            );
    });
</script>

This words great if the leftdiv does not have children div's, but if it has children div, then they are not affected.

How can I write jQuery so that children div's also reduce and expand as their parent div does?

A: 

This will also change the width of all child divs

<script type="text/javascript">
    $(document).ready(function() {

        $("#leftc").hover(
            function mouseover() {
                $(this).css({ width: "190px" });
                $("#leftc div").css({ width: "190px" }); // added this line
                $("#centerc").css({ "margin-left": "195px" });
            },
            function mouseout() {
                $(this).css({ width: "25px" });
                $("#leftc div").css({ width: "25px" }); // added this line
                $("#centerc").css({ "margin-left": "29px" });
            }
            );
    });
</script>

But you shouldn't need to do that. You probably want to check your CSS (use liquid width for child divs.)

ANaimi
Thank you so so much Anaimi..and why shouldn't I be doing this..Can you tell me what is liquid width?
Musa
Also how can I select all children inside the DIV , irrespective of them being a div or not? For eg: I have a Image inside the child div, but the child div get resized whereas image does not..
Musa
@Musa: To select all descendants, regardless of tag type:$("#leftc *"); // * matches any tag.To may only children of #leftc, regardless of tag type:$("#leftc > *"); // > restricts matching to children of #leftc
PatrikAkerstrand
For liquid/dynamic widths you should use percentages, dont use fixed/static widths. To get all children (not only div) see http://docs.jquery.com/Traversing/children
ANaimi