I have function in my JQuery that will fill value in #product_detail with data-name=value, for first time it was success when i tried for second time, it only show first value even when i inspect elemen in data-name is second value.
Here's my HTML code:
// here's my button that to alert
function fillspan(productname) {
$("#product_detail").attr("data-name", productname);
}
//the problem
function showitems() {
var name = $("#product_detail").data("name");
alert(name);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<select onchange="fillspan(this.value)">
<option value="value1">Value1</option>
<option value="value2">Value2</option>
</select>
<span id="product_detail"></span>
<button onclick="showitems()">Click</button>