Mangrommet
Mangrommet

Reputation: 13

If statement not working in ie7

I'm working on a mousedown function, but for some reason my if statement doesn't work in ie7 within the below code. Works in ie8 up, Chrome and FF.

What am I doing wrong?

$("dd.office").mousedown(function() {
    var btnTxt=$(this).text();
    for (var i = 0; i < offices.length; i++) {
      var teOffice = offices[i];
         if (btnTxt==teOffice[0]){  
           alert("Why Doesnt this work in ie7?");
         }
    }                   
}); 

var offices = [
['Office1', -33.3, 151.426039, 2],
['Office2', -33.9, 151.18743, 3],
['Office3', -37.9, 145.156302, 1]
];

page code

<dl>
<dt>Info</dt>
<dd class="office" >Office1</dd>
<dd class="office" >Office2</dd>
<dd class="office" >Office3</dd>
</dl>

Upvotes: 1

Views: 260

Answers (3)

vol7ron
vol7ron

Reputation: 42179

Your btnTxt has a trailing space ().

Do one of the following:

  1. btnTxt = $(this).text().replace(/\s$/,'')
  2. if (btnTxt.replace(/\s$/,'')==teOffice[0]){

Upvotes: 2

Michael Berkowski
Michael Berkowski

Reputation: 270775

You have a trailing comma inside the offices array. IE chokes on trailing commas.

var offices = [
['Office1', -33.3, 151.426039, 2],
['Office2', -33.9, 151.18743, 3],
['Office3', -37.9, 145.156302, 1],
// ------------------------------^
// remove that.
];

Upvotes: 1

DrStrangeLove
DrStrangeLove

Reputation: 11587

$("dd.office").mousedown(function() {
    var btnTxt=$(this).text();
    for (var i = 0; i < offices.length; i++) {
      var teOffice = offices[i];
         if (btnTxt==teOffice[i]){  
           alert("Why Doesnt this work in ie7?");
         }
    }                   
}); 

Upvotes: 0

Related Questions