我正在尝试在单击事件后从我的 js 文件中设置数据 ID 和/或跨度值。
<span id="test"></span>
我的 sudo 代码 js 文件
nextLink: function(event) {
$('#test').val = 3;
$('#test').data('id') = 'Next';
},
我正在尝试在单击事件后从我的 js 文件中设置数据 ID 和/或跨度值。
<span id="test"></span>
我的 sudo 代码 js 文件
nextLink: function(event) {
$('#test').val = 3;
$('#test').data('id') = 'Next';
},
Try setting it as an attribute..
$('#test').attr('data-id' , 'Next'); // JQuery
You can also try the setAttribute()
..
var d = document.getElementById("test"); // Javascript
d.setAttribute('data-id' , 'Next'); //
Using this approach will reflect the new attribute in the DOM
In your code You are trying to set the attribute which is not present .. So you need to add the attribute first to add that ..
You probably need this:
$('#test').data('id', 'Next');