How to add data attribute while creating the element?

You need to insert a data attribute to use for displaying modal window
when you try to add an attribute with a hyphen, of course gives an error

with backgroundImage instead of background-image here, not rolls

the option also point data.toggle

to be escaped with a backslash \ does not help

", { "id": "zoom-map", text: "Zoom in map", data-toggle: "modal", data-target: "#modal-map-body", click: function(){ $(window.parent.document.getElementById('modal-map-body')).addClass('overlay-map').html('<iframe src="*"></iframe>'); $(window.parent.document.getElementById('start-map')).click(); } }).insertAfter("");
July 9th 19 at 12:48
2 answers
July 9th 19 at 12:50
Quoted take
", { "id": "zoom-map", "text": "Zoom in map", "data-toggle": "modal", "data-target": "#modal-map-body", click: function(){ $(window.parent.document.getElementById('modal-map-body')).addClass('overlay-map').html('<iframe src="*"></iframe>'); $(window.parent.document.getElementById('start-map')).click(); } }).insertAfter("");
thanks, so simple :) - larue_Jerde commented on July 9th 19 at 12:53
July 9th 19 at 12:52
', { ... }).insertAfter("").data('toggle', 'modal').data('target', "#modal-map-body");

Find more questions by tags JavaScriptjQuery