jquery - why does this iterate the div twice? -


so i've created erb block iterates through coordinates each image tag ('.tagged'), , displays '.tagged' each image @ given coordinates. in particular case block iterates through 2 images, , .tagged shows on both images instead of 1 tag per respected image. because of .each() method?

<div class="container"> <% if @new_manual.present? %> <% @new_manual.steps.each |step| %>     <% i_connection = contact.find(step.input_contact) %>  <span class="i_connection" data-pos-x="<%= i_connection.pos_x %>" data-pos-y="<%= i_connection.pos_y %>"  data-pos-width="<%= i_connection.pos_width %>" data-pos-height="<%= i_connection.pos_height %>"> </span> <br> <div class="image_panel">     <%= image_tag(i_connection.image.image.url(:large)) %> <div class='planetmap'></div> </div>  <script type="text/javascript"> $(document).ready(function(){ $("span.i_connection").each(function() {     var pos_width = $(this).data('pos-width');     var pos_height = $(this).data('pos-height');     var xpos = $(this).data('pos-x');     var ypos = $(this).data('pos-y');      $(".tagged_box").css("display","block");     $(".tagged").css("border","5px solid red");          $('.planetmap').append('<div class="tagged"  style="width:'+pos_width+'px;height:'+pos_height+'px;left:'+xpos+'px;top:'+ypos+'px;" ><div class="tagged_box" style="width:'+pos_width+'px;height:'+             pos_height+'px;" ></div>') });   //end of span.connection iteration }); //end of jquery </script>    <% end %>    <% end %> </div> 

move block of javascript outside of the

<% @new_manual.steps.each |step| %> 

loop.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -