2

Hello I have the folowing HTML element :

<li class="total_payment" data-basetotal="0.00">
    <span>
        <h5>Total</h5>
    </span>
</li>

I want to change the data-basetotal value from 0.00 to 50.00 with jQuery jQuery v1.7.2 using :

$(document).ready(function(){
$('.total_payment').attr('data-basetotal', '50.00');
});

but it is not working , how can I change the value please?

Thanks

3
  • Looks like that class should be an id if its unique which appears to be. Commented Sep 23, 2015 at 14:47
  • That should work as written, can you reproduce the failure? And define what "not working" means in the context of your question. Commented Sep 23, 2015 at 14:49
  • 4
    It works for me Commented Sep 23, 2015 at 14:52

1 Answer 1

5

Try to use

$('.total_payment').data('basetotal', '50.00');
Sign up to request clarification or add additional context in comments.

1 Comment

This is the preferred way of handling data attributes. As a note though, this won't actually change the data-basetotal attribute on the element; it will only modify the jQuery data object associated with that element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.