Fix JS error when calculating selector offset