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 id="4">

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

Thanks in advance,



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);



For the benefit of the rest of us, would you mind explaining that $() syntax?



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.

My favourite jQuery book - jQuery Pocket Reference - reviews.