Prob getting started

2 views
Skip to first unread message

graha...@gmail.com

unread,
Feb 8, 2008, 3:40:21 PM2/8/08
to DOMAssistant
Greetings all. I am a front end developer for a local county
government in NW Florida, USA and I was having some difficulty getting
started with DOMAssistant. I think that I'm really close to an answer
for my prob, but I just can't get it right. Anway, I am trying to
attach an "onmouseover" event to all <tr>s in a doc to change their
class, but I cant get .addEvent and .addClass to work in combination.
I have something like the following:


function trhover() {
$(document).elmsByTag("tr").addEvent("mouseover", f);
}

function f() {
this.addClass("trhover") // I would think that would work here but it
breaks!!!
}

DOMAssistant.DOMReady(trhover);



I get "this.addClass is not a function" in firebug when I try
this.addClass. I have tried several combinations, including the
new .each feature, but everything I do stops with an error. Can anyone
suggest a solution?

Thanks,
Graham Peel

chenghong

unread,
Feb 9, 2008, 11:13:53 AM2/9/08
to DOMAssistant
Did you include the DOMAssistantCSS.js file? This module is required
for the addClass method.

Or you could just use the DOMAssistantComplete.js file.


On Feb 9, 4:40 am, "graham.p...@gmail.com" <graham.p...@gmail.com>
wrote:

graha...@gmail.com

unread,
Feb 10, 2008, 12:33:47 PM2/10/08
to DOMAssistant
Yeah I'm including the DOMAssistantComplete.js file. I can get
addClass and addEvent to work separately, but not together as I need
to do. If someone could write out the syntax for grabbing a collection
of elements and adding an event to reference a function with addClass,
I'd really appreciate it.

Robert Nyman

unread,
Feb 11, 2008, 4:21:16 AM2/11/08
to domass...@googlegroups.com
Hi Graham,

The reason is that only the elements which are are selected through the $ selector will get the extra DOMAssistant methods added to it.
What this means is that in your function receiving the event, you need to reference "this" with in the same way, like this:

$(this).addClass("trhover");

Another solution can be using CSS selectors to select the elements to begin with, to get aroud it. Like this:

$("body tr").addEvent("mouseover", f);

In the long run, probably in the next version, it will hopefully not be mandatory to use the $ selector in a case such as yours. However, it does help to distinguish anything extra we might want to add to elements, so when in doubt, always surround your element with $.


Best regards,
Robert

graha...@gmail.com

unread,
Feb 11, 2008, 4:53:18 PM2/11/08
to DOMAssistant
Perfect! It works! Thanks again for the help. I'm really enjoying this
compact framework.

On Feb 11, 4:21 am, "Robert Nyman" <rob...@robertnyman.com> wrote:
> Hi Graham,
>
> The reason is that only the elements which are are selected through the $
> selector will get the extra DOMAssistant methods added to it.
> What this means is that in your function receiving the event, you need to
> reference "this" with in the same way, like this:
>
> $(this).addClass("trhover");
>
> Another solution can be using CSS selectors to select the elements to begin
> with, to get aroud it. Like this:
>
> $("body tr").addEvent("mouseover", f);
>
> In the long run, probably in the next version, it will hopefully not be
> mandatory to use the $ selector in a case such as yours. However, it does
> help to distinguish anything extra we might want to add to elements, so when
> in doubt, always surround your element with $.
>
> Best regards,
> Robert
>
> On Feb 10, 2008 6:33 PM, graham.p...@gmail.com <graham.p...@gmail.com>
Reply all
Reply to author
Forward
0 new messages