I use data attributes extensively for managing data in client side events. Is it possible to assign value dynamically to a data attribute using javascript or jquery?
<li data-class_value="somevalue" class="myclass"></li>
$('.myclass').click(function(){
$(this).data('class_value') = "new value";
});
The above javascript code throws the error:
"Uncaught ReferenceError: Invalid left-hand side in assignment".
Could someone please tell me how this can be achieved?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…