Tuesday, 6 August 2013

.width() returns 0 for an image width

.width() returns 0 for an image width

I'm trying to log the width of an image and every thing I try returns 0.
Any idea why? This is what I have so far.
jQuery
var imgWidth = $('#imageMap').width();
console.log(imgWidth);
ERB that generates the image
<% @image.each do |image| %>
<% image.contacts.each do |conn| %>
<span class="connection" data-pos-x="<%= conn.pos_x %>"
data-pos-y="<%= conn.pos_y %>" data-pos-width="<%= conn.pos_width
%>" data-pos-height="<%= conn.pos_height %>"> </span>
<% end %>
<%= f.hidden_field :image_id, value: image.id %>
<%= image_tag(image.image.url(:large), id: 'imageMap') %>
<% end %>

No comments:

Post a Comment