Hi JC,

Best way to do this is by using the Event.observe method
(http://prototypejs.org/api/event/observe)
to attach your fading method to designated divs.

// assign a class name to the divs you want to have the fading behaviour
<div class="fadeable">Click me to fade away</div>
<div class="fadeable">or click me to fade away</div>

// event.target to get the element that fired the click event
function myeffect(event) {
    event.target.fade({ duration: 3.0, from: 1, to: 0 });
}

// on domload, find all elements with fadeable class name
// observe their click event and attach myeffect as its handler
document.observe('dom:loaded', function() {
    $$('.fadeable').invoke("observe", "click", myeffect);
});

That's how i would do it, complete separation between html and its behaviour.

Or of course,  you can also
<div onclick="myeffect(this)">Click me to fade away</div>

function myeffect(zdiv) {
       zdiv.fade({ duration: 3.0, from: 0, to: 1 });
}

But I strongly advice the first approach.

cheers

--
mona
[EMAIL PROTECTED]

On Wed, Nov 26, 2008 at 10:56 PM, justclint <[EMAIL PROTECTED]> wrote:
>
> Im just getting into script.aculo.us by way of cakephp. As for
> javascript frameworks Ive only used jquery.
>
> This question is so basic I cant find anything on past posts here in
> the groups hence this post.
>
> Basically I just took a random effect and it worked as described in
> the github area by applying it to an element selected by id.
>
> Im trying to get the effect to work "not by id" but by "this". Heres
> my example but not working:
>
> script:
> <code>
> <script type="text/javascript" language="javascript">
>  // <![CDATA[
>        function myeffect() {
>        $(this).fade({ duration: 3.0, from: 0, to: 1 });
>        }
>  // ]]>
> </script>
> </code>
>
> html
> <code>
> <div onclick="myeffect()">
>  Click me to fade away
> </div>
> <div onclick="myeffect()">
>  or click me to fade away
> </div>
> </code>
>
> I dont see any documentation on how to apply to "document.this"
>
> Im sure my syntax is wrong but everyway I switch it around it still
> wont work.
>
> What am I doing wrong?
>
> Thanks in advance!
>
> jc
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to