[jQuery] Re: Bug in jQuery selector or am I just not understanding?

2007-11-26 Thread Mark Lacas

All those divs are necessary for the type of system I'm building.

Can't talk about it yet, but when we release I can explain why.

Solved the problem by using the ">" in between my selectors.

I adore jQuery and love becoming smarter about jQuery every day from
this list.  Amazing resource.

ml



[jQuery] Re: Bug in jQuery selector or am I just not understanding?

2007-11-25 Thread Dave Methvin

> I thought the cascading selectors would have chosen the dp_properties
> class that is the first child level of the selected div. . .not the
> dp_properties class buried two levels down (but appearing first in the
> DOM listing).

jQuery selectors work pretty much the same way they do in CSS.

This selects all *descendants* of #mydiv that have class .myclass:

  #mydiv .myclass

This selects all *immediate children* of #mydiv that have
class .myclass:

  #mydiv > .myclass

The "#395 .dp_properties" selector finds two divs and you are only
alerting the dp_id value of the first one.

Also, in a valid HTML4 document, ids can't start with a digit and
there is no dp_id attribute on divs. Invalid HTML may not work on all
browsers.

http://validator.w3.org/


[jQuery] Re: Bug in jQuery selector or am I just not understanding?

2007-11-25 Thread Brett

That code is a bit hard to read
I would have written the html to be more semantic, instead of using
lots of div tags.

Still, the exact code if that was in css should be
div div div div.dp_properties - so you can see why it reads a bit
confusing.

I like the idea of defining a tag and using its info though (dp_id) :)

I'm not sure i've fully answered your question though, so let us know
how  you go.

On Nov 26, 12:24 pm, Mark Lacas <[EMAIL PROTECTED]> wrote:
> Why does the code below show the values for the two alerts to be:
> bilbo and layout_1 ?
>
> I would have expected: bilbo and bilbo.
>
> I thought the cascading selectors would have chosen the dp_properties
> class that is the first child level of the selected div. . .not the
> dp_properties class buried two levels down (but appearing first in the
> DOM listing).
>
> I would have thought that I would have had to use more selectors to
> get into there specifically?
>
> This really breaks my thinking of how jQuery works.  Do I really need
> to know what elements are in between to know that a selector is
> working properly?  What syntax would I use to get the one I want (the
> last and outermost)?
>
> Thoughts, answers, fixes?
>
> Thanks,
> ml
>
> alert( $( "#395" ).attr("dp_id") );
> alert( $( "#395" .dp_properties" ).attr( "dp_id" ) );
>
> 
> 
> 
>  dp_id="layout_1">
> 
> 
> 
>