jQuery .css(“left”) returns “auto” instead of actual value in Chrome

前端 未结 5 1552
感情败类
感情败类 2020-11-30 14:49

I have div element with left and top defined, without absolute position, and I want to read the left and top values using jQuery.

Using $(\"#M

5条回答
  •  温柔的废话
    2020-11-30 15:30

    I know this is an old post, but I ran into this same problem and thought I would suggest a couple of solutions. It seems that this problem is not specific to Chrome, as I was able to reproduce in Firefox as well.

    I was able to solve this one of two ways. Either place you CSS styles in the same file as your HTML, instead of using a separate CSS file. OR, call the function inside of window.onload. Looks like the values are not available to the browser until everything has loaded, IF the styles are in an external style sheet.

    Hope this is helpful.

提交回复
热议问题