Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Last active May 29, 2016 04:46
Show Gist options
  • Save nishinoshake/cf808ce4f7654f5bae35 to your computer and use it in GitHub Desktop.
Save nishinoshake/cf808ce4f7654f5bae35 to your computer and use it in GitHub Desktop.
カスタムデータ属性にアクセス
<p id="blog" data-author="Taro" data-create-date="2013-04-10">2013-04-10</p>
var blog = $("#blog");
alert("author : " + blog.data('author'));
alert("create date: " + blog.data('create-date'));
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