I think this is what you are trying to do:

script:
<code>
<script type="text/javascript" language="javascript">
  // <![CDATA[
        function myeffect(obj) {
        $(obj).fade({ duration: 3.0, from: 0, to: 1 });
        }
  // ]]>
</script>
</code>

html
<code>
<div onclick="myeffect(this)">
  Click me to fade away
</div>
<div onclick="myeffect(this)">
  or click me to fade away
</div>
</code>

but this can be achieved by
<div class="fadeAway">
  Click me to fade away
</div>
<div class="fadeAway">
  or click me to fade away
</div>

$$('fadeAway').observe('click', function(event) {
  var element = event.element();
  $(element).fade({ duration: 3.0, from: 0, to: 1 });
});

actually, I'm not sure if prototype can chain the observe like that,
you might need to:


$$('fadeAway').each(function(obj){
  $(obj).observe('click', function(event) {
    var element = event.element();
    $(element).fade({ duration: 3.0, from: 0, to: 1 });
  });
});


Since you know jQuery, the equivalent in jQuery is:

$('fadeAway').click(function() {
  $(this).fadeOut('slow');
});



On Nov 26, 1: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