In your livequery callback, this is the DOM object that received the
event so your "th.name".

$(this) builds a jQuery around this DOM element, a jQuery around your
"th.name".

$(this).children("th.name") returns a jQuery containing the children
of "th.name" that are "th" elements and have a class "name", so
nothing.

If you want the child "b" element, just do $(this).children("b"). You
can also use $(this).find("b").if you are not sure that "b" is a
direct children of your "th.name".

You may have misunderstood what the "children" method is doing, just
recheck the jQuery documentation.

On Mar 19, 2:45 pm, Martin <martin.ikedia...@gmail.com> wrote:
> The code looks like this
>
> $("th.name ").livequery('click', function() {
>                 var $selected = $(this).children("th.name");
>
>                 if($selected.is(":hidden")){
>                         console.log($selected);
>                         console.log($selected.find("b").length);
>                         
> $selected.find("b").removeClass().addClass("subtraction");
>
>                                 $selected.find("a").hide().end
> ().slideDown("slow", function(){
>                         $selected.find("a").fadeIn();
>                 }, "easeOutCubic");
>
>                                 } else {
>                         $selected.find("b").removeClass().addClass("add");
>                         $selected.find("a").fadeOut(function(){
>                                 $selected.slideUp("slow", "easeInQuart");
>                         });
>                 }
>
> };
>
> On Mar 19, 1:31 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
>
>
>
> > Hi Martin,
>
> > (Disclaimer:  I'm really new at jQuery, though not at DOM scripting.)
>
> > It sounds like you're saying that this line:
>
> > > var $selected = $(this).children("th.name");
>
> > ...isn't finding any matching elements and that that's why you can't
> > find the <b> child of the <th>.  What's the context in which you're
> > executing that line?  Some event handler?  If so, on what element?  It
> > would have to be the immediate parent of the <th> (e.g., a <tr>) for
> > it to find it, since recall that #children finds only _direct_
> > children of the context.
>
> > With a bit more context (no pun!) we can probably figure it out, if
> > the above isn't helpful.
>
> > FWIW,
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Mar 19, 1:20 pm, Martin <martin.ikedia...@gmail.com> wrote:
>
> > > Hello,
>
> > > I am trying to grab the child of element in my html (see below)
>
> > > <th class="name" colspan="4">
> > >                                                                           
> > >               <b class='add'>&nbsp;</b>
> > > </th>
>
> > > I am trying to use this Jquery Code to grab the "b" child element of
> > > "th".  I want to change the class element for b from "add" to
> > > "subtraction"
>
> > > var $selected = $(this).children("th.name");
>
> > > console.log($selected); /*  returns Object length=0 prevObject=Object
> > > context=th.name */
> > > console.log($selected.find("b").length);  /* returns 0 */
>
> > > When I try to select b, for obvious reasons the remove and add class
> > > doesnt work
>
> > > $selected.find("b").removeClass().addClass("subtraction");
>
> > > Does anyone have a solution to this problem?
>
> > > Regards
>
> > > Martin Ikediashi- Hide quoted text -
>
> > - Show quoted text -

Reply via email to