On May 15, 8:45 am, Byron Young <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I couldn't find anything about this on the list or the prototype docs
> or google, so please excuse me if somebody has addressed this
> somewhere.
>
> I'm have some code like this:
>
>     var toggleControllers = $A(form.select('*[show]'));
>
> Which works great in FF - it selects all the items on the page with a
> 'show="something"' attribute.

It is not a good idea to use custom attributes on HTML elements, the
class attribute can provide similar functionality.


>  But in IE it selects everything on the
> page.  If i change the selector to *[anything-other-than-show], it
> works properly.  I couldn't figure out why I was getting this behavior
> until i dumped the contents of element.readAttribute('show') for each
> result in toggleControllers.  This gives me:
>
>     function() {
>       return __method.apply(null, [this].concat($A(arguments)));
>     };
>
> So, it appears that the [attr] selector in IE also selects elements
> with methods named 'attr'.  Or maybe I'm interpreting it wrong and
> Prototype adds extended methods to elements as attributes,

Prototype.js adds methods to DOM elements in browsers like IE in every
function that accepts an element as an argument.


> so maybe
> XPath is doing the right thing?
>
> Is there any way to avoid matching on methods like show() using the
> [attr] selector?  Or do I need to just skip any where
> Object.isFunction(el.readAttribute('attr')) is true?

You also have the problem of masking DOM properties with HTML
attributes in those browsers where Prototype.js adds methods directly
to the DOM element (as it does for IE).

When using Prototype.js, do not use it's element method names as
attribute names on HTML elements, e.g.:

  <button onclick="$(this).hide()" hide="foo">Hide me?</button>

Does not hide the button in IE, since $(this).hide returns the string
"foo", not a reference to the hide method.  It is also possible that
some browsers will add HTML attributes as DOM properties where methods
have been added to the host HTML element prototype object and so may
be "shadowed" in browsers other than IE.

The issue you have discovered is used to argue against adding
properties to host objects, particluarly as a fundamental strategy of
a general purpose library.


--
Rob
--~--~---------~--~----~------------~-------~--~----~
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