Safari Native Code
Solution 1:
[native code]
just means that it's a function that is built in to the browser, rather than written in JavaScript. tags
appears to be a WebKit extension to the DOM to allow you to get a list of elements in the form by tag name. For instance, if I run this on the StackOverflow page, I get the answer text area:
document.getElementById('submit-button').form.elements.tags("textarea")[0]
The issue is that an index into a collection in JavaScript also access any object properties (including methods), so when you try to access your named element tags
, you get instead the method on the elements
object that WebKit defines. Luckily, there is a workaround; you can call namedItem
on the elements list to get an item by id
or name
:
var tags = button.form.elements.namedItem("tags").value;
edit: Note that its probably better to use namedItem
in general even in other browsers, in case you need to retrieve an element named item
or length
or something like that; otherwise, if you use them as an index with the []
operator, you'll get the built in method item
or length
instead of your element.
Post a Comment for "Safari Native Code"