Reputation: 47945
I have this code :
<div class="riga" style="border-top:0;">
<div class="col3" id="txtValoreCatastale">0,00 euro</div>
</div>
<script type="text/javascript">
txtValoreCatastale = $('#txtValoreCatastale');
</script>
seems I get an error :
SCRIPT438: Object doesn't support this property or method
show, Row 33 Char 4
that will Broke (on my whole original code) some of my script! But if I wrote :
var txtValoreCatastale = $('#txtValoreCatastale');
it works perfectly.
Why this behaviour? Another massive bug?
Upvotes: 0
Views: 3071
Reputation: 12018
IE creates its own global variable for every element id you use. So the problem is, IE has already created its own variable called txtValoreCatastale. By adding var in front of it you are telling IE that in the scope of your function it is a local variable and so IE allows it. If you called it some other name like someOtherVariableName it would have worked without var in front.
Upvotes: 1
Reputation: 9980
Just a quick thought: When you specify a DIV with an id, it becomes a global variable with that name. So you already have a global variable called txtValoreCatastale, which is a DOM element. It should work fine if you either change the ID or the variable name.
Upvotes: 4