I’m trying to calculate the widths of each span element with class name alt, subtract that width and then subtract a further 50px from that calculation:
<ul class="items">
<li class="product1 alt"><a href=""><span>Televisions</span></a></li>
<li class="product2"><a href=""><span>MP3 Players</span></a></li>
<li class="product3 alt"><a href=""><span>Speakers</span></a></li>
</ul>
And my jQuery:
function moveIt() {
var diamond = $("#ir-content li.alt a span").width();
$("#ir-content li.alt a span").css("left","-" + theMath - "50px");
alert(theMath);
}
moveIt();
Is this what you’re trying to do?
http://jsfiddle.net/rxw3B/8/
Note, in this answer, the above actually worked with the OP’s markup and css. However, this is probably a better example for posterity (using
position: relative):http://jsfiddle.net/rxw3B/9/