7

HTML 5 has a new data attribute data-*

Given the following usage:

   <ul>
     <li data-animal-type="bird">Owl</li>
     <li data-animal-type="fish">Salmon</li> 
     <li data-animal-type="spider">Tarantula</li> 
   </ul>

How could I access these attribute in Dart.

rolfl
  • 17,539
  • 7
  • 42
  • 76
st_clair_clarke
  • 5,453
  • 13
  • 49
  • 75
  • 3
    Out of the 25 questions you've posted, has truly not a single one been answered correctly? It's tough to know whether answers are helpful if they are not accepted as correct. – zeantsoi Jan 04 '14 at 04:36
  • Please check your facts zeantsoi. – st_clair_clarke Jan 04 '14 at 05:01
  • How so? Would you care to enlighten me? – zeantsoi Jan 04 '14 at 05:02
  • Follow link: http://stackoverflow.com/questions/20406328/how-to-remove-a-child-component-with-a-delete-button-in-the-child-itself – st_clair_clarke Jan 04 '14 at 05:07
  • 1
    What is the point of that link, exactly? My point is that you haven't accepted a single answer to any of your 25 questions – your link _only proves my point_. __In fact__, you've gone as far as to state, ["the answer is exactly what I wanted,"](http://stackoverflow.com/questions/20406328/how-to-remove-a-child-component-with-a-delete-button-in-the-child-itself#comment30529332_20408195) and yet you didn't accept the answer. I'm simply suggesting that if you don't accept any answers, you may not get quality responses. At any rate, I'm done with this discussion. – zeantsoi Jan 04 '14 at 05:10

1 Answers1

5

The Element class contains a dataset property that is designed to access (read and write) data attributes on element. It automatically prefix your attribute names with data, so you don't have to do it yourself:

var animalType = listItemElement.dataset['animalType];

One important thing is, that the dataset attribute converts all attribute names to camel-case. If you have animal-type you need to access animalType.

The data- prefix is required for custom attributes that should not affect the layout in HTML5. If you don't use it, validation of your document might not succeed.

Fox32
  • 13,126
  • 9
  • 50
  • 71
  • 1
    To accept an answer, you need to check the checkbox next to the answer. That is what I suspect zeantsoi is referring to as well. It i sn't enough to say that you accept the answer. You must formally accept it. Cheers. – Shailen Tuli Jan 04 '14 at 13:07
  • 1
    Thanks Fox32. Your single statement on how to accept an answer was worth all the tirade of zeantsoi. It is always best not to assume what is obvious to us is obvious to others. Thanks again. – st_clair_clarke Jan 04 '14 at 23:13
  • @st_clair_clarke you may revisite your old question and accept awnsers there too. Than people like him don't have anything to complain about anymore – Fox32 Jan 04 '14 at 23:49