0

I've got the following piece of code:

vote = $('input.vote', $($("ul#statement_forms li.statement")[current])).attr("value");
alert(vote);

Where the variable current is an integer. If i run this in Safari it works as expected (it alerts the value of vote), but not in IE, though, when i run this:

alert($('input.vote', $($("ul#statement_forms li.statement")[current])).attr("value"));

IE Also alerts the value, so i guess the problem is that it wont assign the value to the variable.

I tried using jQuery 1.5.1, 1.3.1 and 1.2.6 but no difference.

I'm hoping one of you guys can help me out..

Thanks!

Bennie
  • 1
  • 1
  • Whats happens in ie when you do it the first way? it is perfectly valid code which should work just fine. – Martin Jespersen Mar 24 '11 at 15:36
  • Is "vote" a global variable? Is there an element on your page whose "id" is "vote"? – Pointy Mar 24 '11 at 15:45
  • The first way IE just quits running JS, it says "Object doesnt support this property or method" (?!) – Bennie Mar 24 '11 at 15:47
  • Vote isnt a global variable, it's defined at this posted line, and yes there is a div id called vote. Why should that be a problem? – Bennie Mar 24 '11 at 15:48
  • Actually it looks a whole lot like a global variable, given that you didn't declare it with `var`. And it could be a problem because we're talking about IE here ... try calling it "voote" instead of "vote" and see if that makes a difference. – Pointy Mar 24 '11 at 15:52

1 Answers1

2

Vote isnt a global variable, it's defined at this posted line

You're missing var before vote to actually declare the variable at this point. Safari apparently doesn't care, but IE doesn't like it.

On a side note: jQuery has .val() and .val("something") functions to retrieve and set the value of input and select elements.

Powerlord
  • 87,612
  • 17
  • 125
  • 175