开发者

jQuery toggle() img element on document.ready - chrome issue

开发者 https://www.devze.com 2023-03-13 08:17 出处:网络
I try to toggle some elements(labels/fields/img) with jQuery based on the jQuery ends with selector. Everything works fine in IE/Firefox/Safari - but not on Google\'s Chrome. There\'s an issue with im

I try to toggle some elements(labels/fields/img) with jQuery based on the jQuery ends with selector. Everything works fine in IE/Firefox/Safari - but not on Google's Chrome. There's an issue with img elements on the document.ready() function. Chrome does not toggle those img elements.

Any Idea, suggestions? Thank you.

jQuery 1.5.1 Chrome 12.0.742.100

<script type="text/javascript">
$(document).ready(functio开发者_开发技巧n () {
    var v = $('#VNType').val();
    if (v == 'equalToVP') {
        ToggleVisibility();
    }
});

function ToggleVisibility() {
    //jquery ends with selector
    //hide label/fields/img
    $('[id$="VN"]').toggle();
    $('[for$="VN"]').toggle();

}


It is probably due to the fact that ready fires prior to images being loaded. Try load instead and see if it fixes the issue.

$(window).load(function () {
  // run code
});
0

精彩评论

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