var mydiv = $('#mydiv'); $('.childdiv', mydiv).css('font-weght', 'bold');
On Jan 23, 12:57 pm, corb <corbinc...@gmail.com> wrote: > This may obvious, but I haven't seen any examples that fit what I'm > trying to do. In many places in my code, I will select an element once > into a var and make necessary changes. What I can't seem to figure out > or find documentation on is querying on an existing object. > > Here's what I have to do now: > > $().ready(function(){ > $("#mydiv").click(function(){alert('hello')}); > $("#mydiv .childdiv").css("font-weight", "bold");} > > seems a tad inefficient to make two trips through the DOM. > > Here's what I would like to do: > $().ready(function(){ > var mydiv = $("#mydiv"); > mydiv.click(function(){alert('hello')}); > // here's where I'm lost > // find all the element identified as "childdiv" and set its css > mydiv("#childdiv").css("font-weight", "bold"); > // is there a way to do this with out multiple trips to the DOM? > > }