I see.  IIRC you didn't fully explain your use case, so I've been  
shooting in the dark about what you're looking for.

With regard to what you're trying to do, it sounds like a regex match  
is the way to go--I'd simply suggest referencing the href property  
directly, rather than toString() on the element:

el.href.match(regex);


TAG

On Aug 6, 2007, at 3:04 PM, Gilant wrote:

>
> I appreciate your trying to offer more elegant solutions! However I
> don't see how the solution you suggest in any way applies to my
> problem. In your examples you are using prototype's match() to test
> classes. That is of no help to me whatsoever with the problem I tried
> to outline in my OP. Let me try to be more descriptive.
>
> 1) I have a link in the page, and the contents of the href attribute
> of that link contains information I need. For example:
> <a href="#key" id="some_id">Foo</a>
>
> 2) The <a> elements id is already known to me, but the 'key' in
> href="#key" is not. This key is essential for fetching something from
> the server (using AJAX) and updating the page.
>
> 3) Using prototype I've added, on page load, an observer to watch for
> clicks on that link. When clicked, I want to get the key from the href
> and use that in making the AJAX request. Currently, following your
> toString() hint from an earlier post, I am using the following to
> extract the key from the href:
> $('some_id').observe('click', function (el) {
>     var key = Event.element(el).toString().match(/regex/)[1]; //
> better solution for this?
>     new Ajax.Request(Event.element(el), { ... }); // using key in
> there
> });
>
> Which is working under Firefox 2 and IE 7. If there is a more robust
> solution to get the string value of the href such that I can check it
> with a regular expression and extract the key, I would certainly be
> open to giving it a try.
>
> Thanks again,
> Sean
>
> On Aug 6, 3:55 pm, Tom Gregory <[EMAIL PROTECTED]> wrote:
>> On Aug 6, 2007, at 12:00 PM, Gilant wrote:
>>
>>> On Aug 3, 1:01 pm, Tom Gregory <[EMAIL PROTECTED]> wrote:
>>>> Event.element returns an element.  Alert-ing it performs an  
>>>> implicit
>>>> toString().
>>
>>> So, why not just call toString() explicitly if the implicit call
>>> returns the string desired? Indeed:
>>> Event.element(el).toString().match()
>>
>> 1. Because that implementation is fragile: it depends on a browser-
>> specific implementation of an element's toString method.
>>
>> 2. Because there are easier, faster, more descriptive, and more
>> legible ways to do the same thing. The standard DOM methods and
>> Prototype's helper methods are good here.
>>
>> Examples:
>>
>> // Testing the element is an element node, not a text node:
>> $(el).nodeType = 1;  // [1]
>>
>> // Test if element is tr
>> $(el).match('tr'); // [2]
>> $(el).nodeName == "TR";  // [3]
>>
>> // Test if element is tr with class "alternateRow"
>> $(el).match('tr.alternateRow');
>>
>> If the explicit toString() call followed by a regex works, that's
>> great.  I'll still assert there are better was of doing it, but it's
>> your app, so do as you like.  I'm just offering what I believe is a
>> more elegant solution.
>>
>> TAG
>>
>> 1.http://zytrax.com/tech/dom/nodetype.html
>> 2.http://prototypejs.org/api/element/match
>> 3.http://www.javascriptkit.com/domref/nodetype.shtml (part way down)
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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