JQuery .data() not working?
data doesn’t set data-* attributes. It manages a data cache unrelated to data-* attributes. It initializes from data-* attributes if there are any present, but never writes to them. To write to an attribute, use attr. Example: Updated Fiddle var div = $(“<div />”) $(div).attr(“data-foo”, “bar”) console.log($(div)[0].outerHTML) What you’re seeing is just one of the … Read more