how to change the value of a attribute inside a div with jquery
here is the div
<div class="rating" data=""></div>
开发者_如何学Go
what i'm wondering is how i can change the value of data to say the number 5
would something like this work? or its done another way?
$(".rating").attr("data").val("5");
$(".rating").attr("data", "5");
$(".rating").attr("data", "5");
Adhering literally to your question, the right code would be:
$(".rating").attr("data", "5");
However, data is not a valid HTML attribute in anything other than HTML 5.
You might want to consider the jQuery data
method instead, for code that is not coupled to the latest version of HTML.
精彩评论