Let's say: I want to display values from the database into various
<div> elements using AJAX. all the referred elements use the same layout to display the data, the difference only resides in the element id or a minimal procedure to validate data. That's all.
However, I quickly came to the conclusion that I don't have a way to refer a specific element in HTML without use the
id property, and the only alternative that I think was the use of
name property. I know that this property it's only for
<input> in a
<form>,and because this elements are not
<input> this rule doesn't apply (I know that in HTML the rules are not enforced).
The basic idea is to stop using
ids to make my code more reusable.
To pass from this:
<div id='sGroupName1'> +---<div id='elementA1'> | +---<span id='txtA1'> +---<div id='elementB1'> +---<span id='txtB1'> <div id='sGroupName2'> +---<div id='elementA2'> | +---<span id='txtA2'> +---<div id='elementB2'> +---<span id='txtB2'>
<div id='sGroupName1'> +---<div name='elementA'> | +---<span name='txtA'> +---<div name='elementB'> +---<span name='txtB'> <div id='sGroupName2'> +---<div name='elementA'> | +---<span name='txtA'> +---<div name='elementB'> +---<span name='txtB'>
Doing my code in this way, i think will break the HTML5 conformity rules. I know this isn't a problem per se, because I have solved in not orthodox way, but I want to hear what is the best way to deal with this situations.