0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

カスタムデータ属性について

Posted at

初めて知ったカスタムデータ属性について

question_idを非同期通信にするために
jsファイルで取得できないだろうか
という時に使うのが

カスタムデータ属性らしい。

data-question-id="<%= @question.id %>

このようにすることでカスタムデータ属性が作成可能になる。

呼び出す時はjsファイル側で
getAttributeメソッドで呼び出すらしい

document.querySelector('h2[data-question-id]').getAttribute('data-question-id');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?