I'm trying to set the id of a 2nd level obj selected by class and it
doesn't seem to work as I thought it would.

Unfortunately all of the level one objects get the id assignment, not
the level two object.

Here it is before I do the operation:

<div id="obj">
    <div class="obj_level1">
        <div class="obj_level2"></div>
    </div>
    <div class="obj_level1.1"></div>
</div>

Then I do this:

var obj = $("#obj");
//bunch of code
obj.children(".obj_level1 > .obj_level2").attr( "id", "Bob" );

It ends up like this:

<div id="obj">
    <div id="Bob" class="obj_level1">
        <div class="obj_level2"></div>
    </div>
    <div id="Bob" class="obj_level1.1"></div>
</div>

Note the two divs with the same id. . .

Do I have to use:

obj.children(".obj_level1").children(".obj_level2").attr( "id",
"Bob" );

Originally I was using:

$("#obj > .obj_level1 > .obj_level2").attr( "id", "Bob" );

And that worked ok, but I needed the object in a variable as I and
using it repeatedly and didn't want to dereference it every time I use
it, for speed's sake.

Any thoughts as to the correct syntax to do this?

Thanks,
ml

Reply via email to