Hidden Input .text IE Compatibility View issue

Hidden Input .text IE Compatibility View issue

I came across an issue that I was having while trying to handle an ajax call and thought I would pass it along. I wasn't able to fix the problem, but I was able to get around it.

I have a hidden input control, along with a label that I'm populating with data from an ajax call. The call returns a dictionary of multiple clientid keys and values for each. I loop through this list and make the following calls

$($get(clientId)).text({some value});
$($get(clientId)).val({some value});

I do both because I'm using the label to display the result, and the hidden input to have the value available on the server side when posting back. The .text above works on the label and the .val works on the hidden input. Having the calls as such above works great in IE 9 and Chrome. However, as soon as IE 9 goes into compatibility view it pukes. Did a little digging and the $($get(clientId)).text({some value}); actually throws an error of "Unexpected call to method or property access." This is happening because I'm trying to call .text on the hidden input control, but it wasn't just a call to .text that puked, it happens when trying to set the text.

So .text, .text() don't puke, but as soon as you try to set text with .text("test") or any string it pukes. I got around this by wrapping each call in a try catch, and just swallowed the error.

*edit...forgot to mention that I am using jquery v1.8.3