Alaa
Alaa

Reputation: 217

How to hide a div for tag in an asp:Repeater

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

Answers (1)

rtpHarry
rtpHarry

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

Related Questions