image - jQuery not displaying span iteration properly -
so i've created erb block gets coordinates each image tag, in want display tag each image @ said coordinates. however, single tag being displayed, not every tag in iteration. idea why? have .each()?
<% 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> <% end %> <% end %> </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"); if ((xpos !== undefined) && (ypos !== undefined)) { console.log('x:' + xpos + 'px' + ' ' + 'y:' + ypos +'px'); $('.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;display:none;" ></div>') } }); //end of span.connection iteration });
edit changed id's classes , tags show each photo. success! still shows both of them, not respected tag. believe has .each() method.
edit #2 latest code
the block iterates through 2 images. .tagged shows on both images instead of 1 tag per respected image
<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"); // if ((xpos !== undefined) && (ypos !== undefined)) { // console.log('x:' + xpos + 'px' + ' ' + 'y:' + ypos +'px'); $('.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 }); </script> <% end %> <% end %>
it's little hard follow final generated html looks code provided 1 error jumps out span
has class of "i_connection"
while jquery selector looking span class of "connection"
. should cause .each()
not run @ though, might not of problem.
Comments
Post a Comment