If you want to set / update the data-* attribute, you will need quotes if you set the attribute:
$('.class').attr({"data-toggle": "whatever-value", "data-target": "#id"});
Otherwise, he analyzes it as
data-toggle
value
data - toggle
subtracting two variables.
You can also use .data() with
$('.class').data({"toggle": "whatever-value", "target": "#id"});
but does not assign data-* attributes, it just saves the data in jQuery storage system.
source share