Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:40:47+00:00 2026-06-13T19:40:47+00:00

I am using jquery’s .replaceWith() function for a webapp I am designing. My HTML

  • 0

I am using jquery’s .replaceWith() function for a webapp I am designing. My HTML is this:

{% for service in services %}                   
<div id="service" name="name" value="{{service.name}}">
{{service.name}} <a href='main/name/{{service.name}}'> Click if you want to see more </a>
<div id="rating_services">
<form name="rating">
{% csrf_token %}
    <input name="star1" id="star_1" type="radio" class="star" value="1"/>
<input name="star1" id="star_2" type="radio" class="star" value="2"/>
<input name="star1" id="star_3" type="radio" class="star" value="3"/>
<input name="star1" id="star_4" type="radio" class="star" value="4"/>
<input name="star1" id="star_5" type="radio" class="star" value="5"/> 
<input type="submit" class="button" id="submit_btn" value="Rate this agency!">
</form>
{% endfor %}
</div>

And my javascript is this:

$(function() 
{  
$(".button").click(function()
  {  
  $('#rating_services').replaceWith("<div id='thanks'> Thanks! </div>");    
  }
});  

What I want to do is if the user rates. A thanks is displayed instead of the ratings. However, the information is displayed within a for loop (for displaying multiple “agencies”). So, I can only rate one by one, and one at a time at that. How can I change it so that I can rate out of order? I tried to change the div id to {{forloop.counter}}, but then javascript can handle the # and the {{forloop.counter}}. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:40:48+00:00Added an answer on June 13, 2026 at 7:40 pm

    I think you have multiple divs with the ID of “rating_services” as a result of your loop?

    If so, instead of hard-coding the ID of the div you’d like to replace, you should give each of the divs a class (i.e. class="rating_services" instead of id="rating_services"), then retrieve the div dynamically using the jQuery closest() function, as below:

    $(function()
    {
      $(".button").click(function()
        {
          $(this).closest('.rating_services').replaceWith("<div id='thanks'> Thanks! </div>");
        }
      );
    });
    

    More on the closest() function here:
    http://api.jquery.com/closest/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using jQuery I have the following code: var selectedIdsArray = $(#selectId option:selected).map(function(){return this.value;}); var
Using jQuery and given this <ul> <li> <a external=http://stackoverflow.com href=home.htm>Link 1</a> </li> <li> <a
Using Jquery AJAX to get a value from a PHP script. This line works
Using jquery's .css() i am changing the left attributes value to move a div
Using jQuery validation - validating on blur: $('input, select, radio, checkbox').blur(function(){ $(#createAccount).validate().element(this); }); If
Using jQuery 1.6.2 HTML that I'm operating on <select id=langId> <option value=0>Argentina - Spanish</option>
Using jQuery I'm programmatically generating a bunch of div 's like this: <div class=mydivclass
Using jquery, I currently append html to a div on a click event. The
Using jQuery, I am trying to capture and display the value of a div
Using Jquery , I have an array result [<a href=><img src=image1></a>,<a href=><img src=image2></a>] if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.