Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Custom Data Attributes HTML JavaScript CSS Tutorial

Learn to use custom data attributes. Custom data attributes allow authors to create custom data to apply to their HTML elements when no other attributes make sense to use to store extra data. They help extend the information that html elements can communicate to a program or script. Custom data attributes can be accessed through both JavaScript and CSS. example.html <style> body { background: #F3F3F3; } div.rockets { position: absolute; background:url(rocket.jpg) no-repeat; width: 125px; height: 50px; left: 0px; transition: left 0s linear 0s; } div.rockets[data-altitude="100"] { transform: rotate( 10deg ); } </style> <script> var rockets, altitude, speed, distance; function activateRockets(){ rockets = document.querySelectorAll('div.rockets'); for(var i=0; i < rockets.length; i++){ altitude = rockets[i].dataset.altitude; speed = rockets[i].dataset.speed; distance = rockets[i].dataset.rocketDistance; rockets[i].style.top = altitude+"px"; rockets[i].style.transitionDuration = speed+"s"; rockets[i].style.left = distance+"px"; } } window.addEventListener("load", activateRockets); </script> <div class="rockets" data-altitude="100" data-speed="3.5" data-rocket-distance="700"></div> <div class="rockets" data-altitude="200" data-speed="5.0" data-rocket-distance="700"></div>
thumb

JavaScript Videos

General Programming

Flat Icons HTML Code Symbols Discovery JavaScriptHow to Program Code Syntax Highlighter Using JavaScriptFat Arrow Functions JavaScript Programming TutorialJavaScript Arguments Object Function TutorialJavaScript Storage Interface sessionStorage localStorage TutorialMulti Column Layout Grid Programming TutorialCustom Alert Box Programming TutorialCustom Confirm Box Programming TutorialCustom Prompt Box Programming TutorialChange CSS Class Style className Toggle TutorialPartial Print Document Tutorial HTML div ContentClick Outside Close Menu Box TutorialPercent Math Calculations Programming TutorialDual Image Reveal Control TutorialPage Loading Screen Document Preloader TutorialControl Panel Flyout Menu Windows AnimationsCustom Data Attributes HTML JavaScript CSS TutorialFullscreen API JavaScript Code Examples and SpecificationConsole Log Tutorial Chrome Firefox IE BrowsersToggle Function Click Drop Down Menus TutorialChange Tab Text and Window Title On The Fly TutorialDice Roll Programming Tutorial For Web Browser GamesDynamic Lorem Ipsum Placeholder Text TutorialBest HTML Event Handling addEventListener TutorialsetAttribute removeAttribute Methods TutorialDisabled User Handling Redirect WebsiteCapture Keyboard Input Tutorial HTML ApplicationCapture Keyboard Input Condition Logic TutorialChange Style Sheet Using Tutorial CSS Swap StylesheetWeb Page Overlay Tutorial Transparent CoverLights Out For Earth Day Tutorial Dark Page SwitchWindow Size Responsive CSS Layout Stylesheet Change TutorialRead Mouse Coordinates Pointer Position Tutorial