Reputation: 217
How can I display or not display a div in a reapeter according to rating value, by problem inside if/ else block. can any one help me.
<td> <div class="AutoMaticRatingStars floating-left" Rating="<%#DataBinder.Eval(Container.DataItem, "AutomaticRating") %>"> </div>
<div class="NoRatingAvailable floating-left ">
no data
</div>
</td>
$('div[Rating]').each(function () {
if (this.getAttribute("Rating") == "" || this.getAttribute("Rating") == 0) {
$(".NoRatingAvailable").css("display", "inline");
$(".AutoMaticRatingStars").css("display", "none");
}
}
);
Upvotes: 0
Views: 113
Reputation: 13125
Hey you should use html5 data attributes if youre working using modern techniques:
<td>
<div class="AutoMaticRatingStars floating-left" data-rating='<%# DataBinder.Eval(Container.DataItem, "AutomaticRating") %>'></div>
<div class="NoRatingAvailable floating-left">no data</div>
</td>
$('.AutoMaticRatingStars').each(function () {
if ($(this).data("rating") == 0) {
$(this).parent().find(".NoRatingAvailable").css("display", "inline");
$(this).css("display", "none");
}
});
I changed the jQuery around a bit too. If your code had worked then it would have set every rating star on the page to invisible not just the current one.
Upvotes: 1