Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Am I the only one who doesn't see the point in having this kind of names for IDs/classes ? Obfuscation maybe? That, off course, doesn't make much sense with tools like Firebug :)


It might be useful for programmers in other languages, so they don't have to either come up with english names, less descriptive names ("id1"), transliterating words, or replacing letters with "similar" ones ("O" or "OE" for "Ø")

Funnily enough, I just registered here, trying to use my first name Øystein, and what did ol' hackernews tell me? "Usernames can only contain letters, digits, dashes and underscores"


How un-HTML5 of HackerNews!


How un-Unicode of HackerNews!


So mine got downvoted? I should have added </sarcasm> there…


It's nice to make an id called "school[school_id][4]" to match the name attribute of the input field.

(In case you don't recognize it php will automatically turns names that look like that into an array.)

Or if you are trying to name fields from a multi dimensional array. Say name['foo']['bar'] - you would name the id name_foo_bar

Simple enough, except when you also have an array: name['foo_bar'] - which looks identical to the first one.

Now that you can use other characters besides _ to separate the fields that helps a ton.


>>(In case you don't recognize it php will automatically turns names that look like that into an array.)

PHP does not have access to IDs of HTML elements. Or did you mean something else?


He meant the name attributes on form elements.

When a form containing <input type="text" name="foo" value="bar"> is submitted, $_POST['foo'] === 'bar' in PHP. (And it works similarly for other server-side programming languages.)


That's true, but not at all what he means. He means:

  <input type="text" name="foo[bar][]" value="yaw" />
will result in:

  $_POST['foo'][0] === "yaw";
In other words you can have a form create multidimensional arrays.


I was merely replying to the “PHP does not have access to IDs of HTML elements” statement, but good job on the additional explanation.


There’s no ‘point’, it’s just awesome that it’s possible, and that HTML5 unifies class and ID restrictions.


The jQuery metadata plugin makes elegant use of this property of class names.

For example, you can do something like this:

<a href="#hello" class="{name:'George'}" />

and then in jQuery you can retrieve the metadata like so:

$('a').metadata('name'); // returns "George"

Its incredibly useful for associating metadata with DOM elements without breaking the HTML's validity.


Isn't this what the data-* attributes should be used for though? Storing that kind of stuff in the `class` attribute seems semantically flawed. http://html5doctor.com/html5-custom-data-attributes/


Ick. I think I'd rather just break my HTML and add random attributes.


Why is that better? You can use JSON here.

(I say this as someone who used to use random HTML attributes.)


I find it aesthetically displeasing, and I'm not convinced that abusing the class attribute to store metadata is "more correct" than just adding your own attributes which.


HTML5 has a proposal for a proper way to do this:

http://dev.w3.org/html5/spec/elements.html#embedding-custom-...


This works now, in all relevant browsers, which is what I need.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: