Hi anathema, sorry if my post is too late :-) , i hope you have already 
found the answer.

Here is the source code (except prototype.js of course) to get your "this"

<html>

<head>
  <script type="text/javascript" 
src="prototype/prototype-1.6.0.2.js"></script>
  <script type="text/javascript">
    function getContentAlt(event, col2, col3){
      alert(event); // your event
      alert(Event.element(event));  // your "this", the element clicked
      alert(Event.element(event).id); // element's id makes sure you get 
the right element
      Event.stop(event);  // stop event
     
      // do what you want to do
    }
   
    Event.observe(document, 'dom:loaded', function(){
      var col2 = '/includes/content/contact-col-2.php';
      var col3 = '/includes/content/contact-col-3.php';
      Event.observe('link1', 'click', 
getContentAlt.bindAsEventListener(false, col2, col3));
      Event.observe('link2', 'click', 
getContentAlt.bindAsEventListener(false, col2, col3));
      Event.observe('link3', 'click', 
getContentAlt.bindAsEventListener(false, col2, col3));
      Event.observe('link4', 'click', 
getContentAlt.bindAsEventListener(false, col2, col3));
    });
  </script>
</head>

<body>
  <a id="link1" href="somefile1.html">Link 1</a><br />
  <a id="link2" href="somefile2.html">Link 2</a>
  <div id="link3">Link 3</div>
  <span id="link4">Link 4</span>
</body>

</html>

anathema wrote:
> Thanks for the added reply Justin, although I am just confused now. I
> think I need some newbie hand holding.
>
>
> Maybe I should explain the ultimate goal. The function getContentAlt
> set up to be reusable. I pass variables col2 and col3 depending on
> which link is clicked. I would set up multiple Event.observe's for
> this.That function needs to know what 'this' is because the first if
> statement tests to see if the class name is 'current' or not. if it
> is, it does not follow through with the function and does not follow
> the link.
>
> Right now the function does not know what 'this' is I presume, because
> I get this error....
>
>
> $(this).hasClassName is not a function
> getContentAlt("/includes/content/contact-col-2.php", "/includes/
> content/contact-col-3.php")functions.js (line 369)
> (no name)()
> wrapper(click clientX=0, clientY=0)
>  if ($(this).hasClassName('current')) {
>
>
> On Apr 17, 9:28 pm, anathema <[EMAIL PROTECTED]> wrote:
>   
>> Maybe I am confused as to where to put Event.stop(event) because the
>> link still gets followed.
>>
>> On Apr 17, 9:09 pm, kangax <[EMAIL PROTECTED]> wrote:
>>
>>     
>>>> Event.observe(window, 'load', function() {
>>>>         
>>> It might be better to listen to 'dom:loaded' event on a document
>>> (since it fires as soon as DOM is ready)
>>>       
>>>>                 Event.observe('emailus', 'click', getContentAlt(col2, 
>>>> col3));
>>>>         
>>> Event.observe needs a function reference as a third argument. You
>>> probably meant to do:
>>>       
>>> Event.observe('emailus', 'click', function(){ getContentAlt(col2,
>>> col3) });
>>> // or
>>> $('emailus').observe('click', function() { getContentAlt(col2,
>>> col3) });
>>>       
>>>> function getContentAlt(col2, col3) {
>>>>         
>>>>                 if ($(this).hasClassName('current')) {
>>>>         
>>>>                         return false;
>>>>         
>>>>                         }
>>>>         
>>> return false; wouldn't work in Event.observe. You need to use
>>> Event.stop(event).
>>>       
>>> Best,
>>> kangax
>>>       

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to