Phoenix
Phoenix

Reputation: 1075

How to solve this jquery selector which in IE 8 doesn't work but IE 9 and firefox 8 work

The element is:

<input type="text" name="idName" id="idName" value="" size="2" maxlength="2" />

I use this selector: alert($('#idName').val());

In IE 8: cannot alert the content

In IE 9 and firefox 8: can alert the content

why? How to fix?

Upvotes: 2

Views: 91

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195992

Make sure the code that calls the alert($('#idName').val()); is inside a $(document).ready(function(){..}); part, so that it runs after the DOM is ready..

$(function(){
    alert($('#idName').val());
});

Upvotes: 3

Related Questions