0

Hi,

I have a div element which have a lot of other divs inside. Inside that divs are also div elements. Now, how can I change width of every div element inside wanted div using jquery (all levels of children). Example

<div id="1">
    <div id="2">
        <div id="3">
        </div>
    </div>
    <div id="4">
    </div>
</div>

Now, I want to change width of all those divs.

Thanks in advance,

Amer

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by MartinRinehart
0

Aldm,

If you want to exclude the outermost div then try:

$("div#1 div").css('width', 500);

If you want to include the outermost div then try:

$("div#1, div#1 div").css('width', 500);

Airshow

0

Martin,

Aldm asked for a jQuery solution.

$ is a synonym for jQuery and the strings in parentheses immediately following a $ are selectors.

jQuery selectors are a very powerful way to select one or more dom elements using one of three syntaxes - css, html or xpath.

A basic $("selector") statement returns a jQuery object with an internal array containing references to each selected dom element (in dom order). The returned object can be assigned to a variable, eg. var foo = $("selector") , but far more significantly, jQuery provides for "method chaining".

For example, $("p.old").css('background-color','#666').parent().find("button.delete").show() - which reads, "find all paragraphs with class='old', set their background color to dark grey, then find the parent element of each of these paragraph's, then find a button with class="delete" within each parent element, and show it".

The range of available selectors combined with a very comprehensive set of native methods, plus plugins, makes jQuery very very powerful. As they say "write less, do more". If you take to it, then it is also quite addictive.

jQuery
My favourite jQuery book - jQuery Pocket Reference - reviews.

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.