Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create HTML data attributes in Elm?

Tags:

elm

I need to tag my Elm.Http elements with custom "data-*" attributes, for example:

<tr data-row="1">...</tr> 

I have tried the following:

import Html exposing (..) import Html.Attributes exposing (..) import Json.Encode as JsEncode  view ... =   tr [ property "data-row" (JsEncode.string (toString 1)) ] 

But this does nothing. Anyone know a way?

I think the problem is that Elm is actually setting JavaScript DOM attributes, so I really want to call element.dataset.row = "1" somehow.

The background is I need to expose some data to jQuery for my event handlers, because the Elm event library is missing a bunch of features I need, such as conditional preventDefault and form serialization. There are other ways to supply data via the DOM, but data-* attributes are by far the most straightforward.

like image 523
wmakley Avatar asked Oct 29 '15 17:10

wmakley


People also ask

How write data attribute in HTML?

HTML data-* Attribute The data-* attribute consist of two parts: The attribute name should not contain any uppercase letters, and must be at least one character long after the prefix "data-" The attribute value can be any string.

Which tag is used for data attribute in HTML?

HTML <data> Tag.

What is data value attribute in HTML?

The HTML data value attribute is used to Specify the machine-readable translation of the content of the element.


1 Answers

You can use the attribute function instead.

view ... =     tr [ attribute "data-row" "1" ] 
like image 69
robertjlooby Avatar answered Sep 22 '22 06:09

robertjlooby