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