I'm trying to run some conditional javascript to position a div such that, if a marker is clicked that is on the right hand side of a photo, the marker tooltip will be positioned to the left of the marker, otherwise it will be to the right of the marker. So, if the marker is on the right, I instruct the tooltip to be positioned at the marker's position().left, minus the width of the tooltip. However the tooltip width always changes, depending on the text inside, and calling jquery's width() function does not return a proper width. Any ideas on how to fix this? Here's the example:
and here's my code:
var tagPos = $photo_tag.position();
if (isNarrow == true){
var photoWidth = $('#photo_box').width();
if (tagPos.left > photoWidth/2){
var brandWidth = $('.brand_name').width(); //MH - NOT WORKING
$brand_name_container.css({'left' : tagPos.left-brandWidth, 'top' : tagPos.top+brandAdjTop});
} else {
$brand_name_container.css({'left' : tagPos.left+brandAdjLeft, 'top' : tagPos.top+brandAdjTop});
}
}