开发者

Jquery Selector not working in IE7

开发者 https://www.devze.com 2023-03-16 22:19 出处:网络
For the following HTML <div id=\'parent\'> <input id=\'child\' type=hidden value=\'\'/> </div>

For the following HTML

<div id='parent'> 
  <input id='child' type=hidden value=''/>
</div>

I am doing

开发者_高级运维$('#parent #child').val('test')

OR

$('#parent > #child').val('test')

but none of the above is working in IE7. It does work in Firefox though

Any idea why is it not working ?


is it because you've got the HTML wrong? You should use " for attribute values. Sometimes IE is more sensitive to these things than Firefox


Your syntax seems correct. The only stuff I can think of that can muck this up are:

  • Make sure you've got your code between a $(document).ready() block
  • Maybe try .prop() instead of .attr() if you're using jQuery 1.6+


Try $('#child').val('test'); which would probably give the same result.

0

精彩评论

暂无评论...
验证码 换一张
取 消