-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Accessing data through data attribute
Scott Erickson edited this page Feb 10, 2016
·
2 revisions
You want to reference the data stored inside a element's data attribute
Use jQuery's built-in data accessing method data('data_tag')
.
Given an element with a properly formatted data tag: data-[data_tag]
.
- var helloWorld = "Hello, World!";
div#foo(data-bar=helloWorld)
Use jQuery's data function, we find the data assigned to data-bar
.
elem = $('#foo') # Returns a jQuery object.
importantString = elem.data('bar') # Pulls the data from the 'bar' data field.
console.log importantString # Output: Hello, World!
- jQuery
- data()
- [CoffeeScript] (http://coffeescript.org/)
- Jade
CodeCombat | Home | Blog | Forum | Teachers | Legal | Contribute
- Home
- Archmage Home
- Artisan Home
- Diplomat Home
- Archmage General
- Mission statement
- Coco Models
- Coding Guidelines
- Cookbook
- File system
- JSON Schema
- Technical overview
- Testing
- Third party software and services
- Artisan General
- Building A Level
- Coding Guidelines for Artisans
- Editing Thang Components
- Important Artisan Concepts
- Keyboard Shortcuts
- Debugging
- Artisan How-To Index
- Diplomat General
- i18n
- i18n Glossary nb
- i18n Glossary ru
- i18n Glossary es-419
- Dev Setup
- Dev Setup: Linux
- Dev Setup: Windows
- Dev Setup: Mac
- Dev Setup: Vagrant
- Dev Setup: Issues
- Game Engine
- Component
- Multiplayer
- Surface
- System
- Thang
- Thang Component System
- Tome
- World
- Artisan Tabs
- Components And Systems
- Scripts
- Settings
- Thangs
- Other
- Aether
- Client models
- Developer organization
- Educational Standards
- Events, subscriptions, shortcuts
- Chat Room
- Chat Room Rules
- Permissions
- Project Ideas List
- Treema
- Versioning
- Views