Home › Forums › JavaScript › Jquery to append each closest element
- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
October 23, 2013 at 11:07 am #153868bcintegrity1Participant
I am using
.get
to retrieve data to obtain a “star rating average” for members listed on my site. The averages will then be appended to.rating
within each member’s listing.I have no problem “getting” each member’s review file (thanks to @Mottie and @vindicateme), and counting the number of five star reviews. The problem is, EACH total is appended to EVERY
.rating
.My test page shows this well. Kim has one review, David has two reviews. But “21” is appended to each of their listings :^( I will work out the details to obtain each average after I get this working.
HTML
<li class="services"> <div class="lpic"> <div class="lbox hbox"> <div class="pro"><img src="images/DavidHarper-list.jpg" /> <p>David Harper<br /> (804) 938-6500<br /> Dodson Pest Control</p> <div class="proviewtab"><p3>Reviews</p3></div></div> <div class="rating">AVERAGE RATING</div> <div class="ratingimage"></div></div></div></li> <li class="services"> <div class="lpic"> <div class="lbox hbox"> <div class="pro"><img src="images/KimMedina.jpg" /> <p>Kim Medina<br /> (804) 381-8026<br /> Dodson Pest Control</p> <div class="proviewtab"><p3>Reviews</p3></div></div> <div class="rating">AVERAGE RATING</div> <div class="ratingimage"></div></div></div></li>
My code
$('.lbox').each(function(event) { var name = $(this).find("p").text(); name = name.split(/^(\w+)\s+(\w+)/); var firstName = name[1]; var lastName = name[2]; var folder = "reviews-pest-control-va"; var reviewsPath = folder + '/' + lastName + ',' + firstName + '.php'; reviewsFile = reviewsPath.toLowerCase(); $.get(reviewsFile, function (data) { var $reviewFive = $(data).find(".five"); var $review5 = $reviewFive.length; $('.rating').append($review5); }); });
Thanks for any help!
October 23, 2013 at 1:48 pm #153879bcintegrity1ParticipantI shortened the code for simplicity, but still the same issue.
$('.lbox').each(function(event) { var name = $(this).find("p").text(); name = name.split(/^(\w+)\s+(\w+)/); var firstName = name[1]; var lastName = name[2]; var folder = "reviews-pest-control-va"; var reviewsPath = folder + '/' + lastName + ',' + firstName + '.php'; reviewsFile = reviewsPath.toLowerCase(); $.get(reviewsFile, function (data) { var $reviewFive = $(data).find(".five").length; $('.rating').append($reviewFive); }); });
October 25, 2013 at 3:14 pm #154071bcintegrity1Participant -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.