SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
HTML5
Data Attributes

     Lennart Schoors
The problem
. improper/impractical/invalid use of
 HTML attributes
  . rel="ajax" or rel="dialog"
  . class="ignore-proxy"
  . custom attributes with custom DTD
The solution: data-* attributes
  . “Custom data attributes are intended to
      store custom data private to the page or
      application, for which there are no more
      appropriate attributes or elements”
  . at least one character after the hyphen
  <span data-age="29">lensco</span>
  <a href="/foo" data-target="dialog">bar</a>



http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes
. private in the sense that the end user
 can't see it - it doesn't affect layout or
 presentation
. intended for use by the site's own scripts,
 not a generic extension mechanism for
 publicly-usable metadata
Support?
. any browser that supports HTML5
 doctypes (= all browsers we support)
. JavaScript API
JavaScript API
. dataset property
. very similar to the the attributes property
. but: not implemented yet, so ...
. use getAttribute & setAttribute
<span data-city="Gent">lensco</span>




var user = document.getElementsByTagName("span")[0];

user.dataset["city"]; // not supported yet!
user.getAttribute("data-city"); // fallback
jQuery
. As of jQuery 1.4.3 HTML5 data-* attributes
  will be automatically pulled in to
  jQuery's data object

user.data("city");
Examples
. store parameters for a Flash movie that’s
 loaded via JavaScript
. store the initial height or opacity of an
 element which might be required in later
 JavaScript animation calculations
. tracking traffic

          http://html5doctor.com/html5-custom-data-attributes
   http://jasonkarns.com/blog/2010/03/10/google-analytics-tagging
Example: lazy image loading
. Flickr: data-defer-src
. "any image that doesn’t need to be loaded
  straight away, including avatars and map
  tiles"
. but: "It’s worth noting that on Flickr we’ve
  disabled this type of image deferral for
  IE6, 7 and 8."

       http://24ways.org/2010/speed-up-your-site-with-delayed-content
 http://24ways.org/2010/speed-up-your-site-with-delayed-content#c007948
When not to use it
. not intended to compete with
  microformats (public data)
. not if there is an existing attribute or
  element which is more appropriate
. don't use as a CSS hook for styling
That’s all folks!
Questions?




Read on at http://lensco.be

Contenu connexe

Tendances

Data Binding - Android by Harin Trivedi
Data Binding - Android by Harin TrivediData Binding - Android by Harin Trivedi
Data Binding - Android by Harin Trivediharintrivedi
 
Trivento Summercamp : Reactive with AngularJS & TypeSafe
Trivento Summercamp : Reactive with AngularJS & TypeSafeTrivento Summercamp : Reactive with AngularJS & TypeSafe
Trivento Summercamp : Reactive with AngularJS & TypeSafeHenk Jurriens
 
Data Collection and Consumption
Data Collection and ConsumptionData Collection and Consumption
Data Collection and ConsumptionBrian Greig
 
JS libraries and frameworks - Quick Tips on Coffee@DBG
JS libraries and frameworks - Quick Tips on Coffee@DBGJS libraries and frameworks - Quick Tips on Coffee@DBG
JS libraries and frameworks - Quick Tips on Coffee@DBGDeepu S Nath
 
Web Programming - 8 Database, Model and Eloquent
Web Programming - 8 Database, Model and EloquentWeb Programming - 8 Database, Model and Eloquent
Web Programming - 8 Database, Model and EloquentAndiNurkholis1
 
Opening up: bibliographic data sharing & interoperability
Opening up: bibliographic data sharing & interoperabilityOpening up: bibliographic data sharing & interoperability
Opening up: bibliographic data sharing & interoperabilityBethan Ruddock
 
Web Programming - 9 Create, Read, Update and Delete
Web Programming - 9 Create, Read, Update and DeleteWeb Programming - 9 Create, Read, Update and Delete
Web Programming - 9 Create, Read, Update and DeleteAndiNurkholis1
 

Tendances (9)

Fast mobile web apps
Fast mobile web appsFast mobile web apps
Fast mobile web apps
 
Data Binding - Android by Harin Trivedi
Data Binding - Android by Harin TrivediData Binding - Android by Harin Trivedi
Data Binding - Android by Harin Trivedi
 
Trivento Summercamp : Reactive with AngularJS & TypeSafe
Trivento Summercamp : Reactive with AngularJS & TypeSafeTrivento Summercamp : Reactive with AngularJS & TypeSafe
Trivento Summercamp : Reactive with AngularJS & TypeSafe
 
01 Ajax Intro
01 Ajax Intro01 Ajax Intro
01 Ajax Intro
 
Data Collection and Consumption
Data Collection and ConsumptionData Collection and Consumption
Data Collection and Consumption
 
JS libraries and frameworks - Quick Tips on Coffee@DBG
JS libraries and frameworks - Quick Tips on Coffee@DBGJS libraries and frameworks - Quick Tips on Coffee@DBG
JS libraries and frameworks - Quick Tips on Coffee@DBG
 
Web Programming - 8 Database, Model and Eloquent
Web Programming - 8 Database, Model and EloquentWeb Programming - 8 Database, Model and Eloquent
Web Programming - 8 Database, Model and Eloquent
 
Opening up: bibliographic data sharing & interoperability
Opening up: bibliographic data sharing & interoperabilityOpening up: bibliographic data sharing & interoperability
Opening up: bibliographic data sharing & interoperability
 
Web Programming - 9 Create, Read, Update and Delete
Web Programming - 9 Create, Read, Update and DeleteWeb Programming - 9 Create, Read, Update and Delete
Web Programming - 9 Create, Read, Update and Delete
 

Similaire à HTML5 data attributes

Single page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiSingle page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiAlexander Zeitler
 
Harness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkHarness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkBorisMoore
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Marios Fakiolas
 
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...James Gallagher
 
Creating Great Applications in SharePoint 2010 with Silverlight 4
Creating Great Applications in SharePoint 2010 with Silverlight 4Creating Great Applications in SharePoint 2010 with Silverlight 4
Creating Great Applications in SharePoint 2010 with Silverlight 4Boston Area SharePoint Users Group
 
Web Apps and more
Web Apps and moreWeb Apps and more
Web Apps and moreYan Shi
 
Web app and more
Web app and moreWeb app and more
Web app and morefaming su
 
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...Roni Banerjee
 
Web Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.xWeb Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.xPatrickHillert
 
Web Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.xWeb Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.xinovex GmbH
 
Web Components v1
Web Components v1Web Components v1
Web Components v1Mike Wilcox
 
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010Patrick Lauke
 
Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)Adam Lu
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Sadaaki HIRAI
 
HTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsHTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsIvano Malavolta
 

Similaire à HTML5 data attributes (20)

Html5
Html5Html5
Html5
 
Single page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiSingle page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web api
 
Html5
Html5Html5
Html5
 
Harness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkHarness jQuery Templates and Data Link
Harness jQuery Templates and Data Link
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...
 
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
IBM Connections Activity Stream 3rd Party Integration - Social Connect VI - P...
 
Synopsis
SynopsisSynopsis
Synopsis
 
Creating Great Applications in SharePoint 2010 with Silverlight 4
Creating Great Applications in SharePoint 2010 with Silverlight 4Creating Great Applications in SharePoint 2010 with Silverlight 4
Creating Great Applications in SharePoint 2010 with Silverlight 4
 
Web Apps and more
Web Apps and moreWeb Apps and more
Web Apps and more
 
Web app and more
Web app and moreWeb app and more
Web app and more
 
HTML5 Refresher
HTML5 RefresherHTML5 Refresher
HTML5 Refresher
 
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
 
Web Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.xWeb Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.x
 
Web Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.xWeb Components mit Polymer und AngularJS 1.x
Web Components mit Polymer und AngularJS 1.x
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010
 
Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
HTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsHTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile apps
 

Plus de Lennart Schoors

Data, taste & confidence
Data, taste & confidenceData, taste & confidence
Data, taste & confidenceLennart Schoors
 
Web design for right-to-left languages
Web design for right-to-left languagesWeb design for right-to-left languages
Web design for right-to-left languagesLennart Schoors
 
Managing CSS for a big ass website - at Netlog
Managing CSS for a big ass website - at NetlogManaging CSS for a big ass website - at Netlog
Managing CSS for a big ass website - at NetlogLennart Schoors
 
To Hell with Web Safe Fonts
To Hell with Web Safe FontsTo Hell with Web Safe Fonts
To Hell with Web Safe FontsLennart Schoors
 
Html 5 in a big nutshell
Html 5 in a big nutshellHtml 5 in a big nutshell
Html 5 in a big nutshellLennart Schoors
 

Plus de Lennart Schoors (6)

Data, taste & confidence
Data, taste & confidenceData, taste & confidence
Data, taste & confidence
 
Look ma! No images!
Look ma! No images!Look ma! No images!
Look ma! No images!
 
Web design for right-to-left languages
Web design for right-to-left languagesWeb design for right-to-left languages
Web design for right-to-left languages
 
Managing CSS for a big ass website - at Netlog
Managing CSS for a big ass website - at NetlogManaging CSS for a big ass website - at Netlog
Managing CSS for a big ass website - at Netlog
 
To Hell with Web Safe Fonts
To Hell with Web Safe FontsTo Hell with Web Safe Fonts
To Hell with Web Safe Fonts
 
Html 5 in a big nutshell
Html 5 in a big nutshellHtml 5 in a big nutshell
Html 5 in a big nutshell
 

Dernier

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 

HTML5 data attributes

  • 1. HTML5 Data Attributes Lennart Schoors
  • 2. The problem . improper/impractical/invalid use of HTML attributes . rel="ajax" or rel="dialog" . class="ignore-proxy" . custom attributes with custom DTD
  • 3. The solution: data-* attributes . “Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements” . at least one character after the hyphen <span data-age="29">lensco</span> <a href="/foo" data-target="dialog">bar</a> http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes
  • 4. . private in the sense that the end user can't see it - it doesn't affect layout or presentation . intended for use by the site's own scripts, not a generic extension mechanism for publicly-usable metadata
  • 5. Support? . any browser that supports HTML5 doctypes (= all browsers we support) . JavaScript API
  • 6. JavaScript API . dataset property . very similar to the the attributes property . but: not implemented yet, so ... . use getAttribute & setAttribute
  • 7. <span data-city="Gent">lensco</span> var user = document.getElementsByTagName("span")[0]; user.dataset["city"]; // not supported yet! user.getAttribute("data-city"); // fallback
  • 8. jQuery . As of jQuery 1.4.3 HTML5 data-* attributes will be automatically pulled in to jQuery's data object user.data("city");
  • 9. Examples . store parameters for a Flash movie that’s loaded via JavaScript . store the initial height or opacity of an element which might be required in later JavaScript animation calculations . tracking traffic http://html5doctor.com/html5-custom-data-attributes http://jasonkarns.com/blog/2010/03/10/google-analytics-tagging
  • 10. Example: lazy image loading . Flickr: data-defer-src . "any image that doesn’t need to be loaded straight away, including avatars and map tiles" . but: "It’s worth noting that on Flickr we’ve disabled this type of image deferral for IE6, 7 and 8." http://24ways.org/2010/speed-up-your-site-with-delayed-content http://24ways.org/2010/speed-up-your-site-with-delayed-content#c007948
  • 11. When not to use it . not intended to compete with microformats (public data) . not if there is an existing attribute or element which is more appropriate . don't use as a CSS hook for styling
  • 12. That’s all folks! Questions? Read on at http://lensco.be