I knew about :input, but my brain just pre-supposed it meant only
input elements so I had kind of disregarded them somewhat.
So thanks for pointing that out!
On Feb 11, 2008 10:07 AM, Dave Stewart [EMAIL PROTECTED]
wrote:
Hi Aaron,
Good styles there with the name attribute stuff. Not so good if you
want to grab other entities such as selects
This should select any form element (input,select,textarea,button) whose
name attribute is foo[bar][baz]:
Hey Marty,
I couldn't live without PHP's square brackets. I just about always
want to split up a form into component parts.
I could easily write something using RegExp to do this for me, but
having it all built in is just lovely.
Great that Rails has it too.
Cheers,
Dave
Hi Aaron,
Good styles there with the name attribute stuff. Not so good if you
want to grab other entities such as selects, but good to see that it
accepts non-standard characters.
All Browsers assign form data variable names according to the name
attribute, not id.
PHP uses square brackets as a shortcut to automagically build arrays
from the request data. Like Karl said, this is illegal in HTML, and
still seems not allowed in XHTML according to
Actually, according to the HTML 4.01 spec, the name attribute on input
elements[1] is defined as being of type CDATA[2], which is very permissive
in the kinds of characters it allows. There is a section in the XHTML
1.0spec that talks about restricting the allowed characters in the
name
Pre jquery I have used an id without the square brackets and a name
with the square brackets. I used the id in my javascript and the form
would submit with the name.
Ken
On Feb 7, 6:28 am, Dave Stewart [EMAIL PROTECTED] wrote:
I'm finding it impossible using jQuery to select any attributes
OK - this is the best I could come up:
function $$(selector, context){
return jQuery(selector.replace(/(\[|\])/g, '\\$1'),
context)
}
$$('#contact[email]')
It adds to the global namespace (so won't work with prototype for
example, which also uses
You can use square brackets, you just have to put a '\' before them
(which has to be done as '\\' because of JavaScript's encoding)
http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_element_that_has_weird_characters_in_its_ID.3F
Karl
On Feb 8, 2008 1:28 AM, Dave Stewart
Wow, that's really useful to know, thanks Karl.
I think I'll just use a regular expression:
selector = selector.replace(/(\[|\])/g, '\$1')
It would be really useful if this were an option, somehow. My jQuery-
foo is not all that.
Any ideas, anyone?
Cheers,
Dave
Remember also that technically in HTML id and name attributes
can't contain '[]'s.
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens (-),
underscores (_), colons (:), and periods (.).
-
11 matches
Mail list logo