Last active
May 29, 2016 04:46
-
-
Save nishinoshake/cf808ce4f7654f5bae35 to your computer and use it in GitHub Desktop.
カスタムデータ属性にアクセス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p id="blog" data-author="Taro" data-create-date="2013-04-10">2013-04-10</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var blog = $("#blog"); | |
alert("author : " + blog.data('author')); | |
alert("create date: " + blog.data('create-date')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var blog = document.getElementById("blog"); | |
alert("author : " + blog.dataset.author); | |
alert("create date : " + blog.dataset.createDate); //JSではハイフンの後create-dateをキャメル(createDate)に |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment