2

As title,I cannot get DOM attrbute by jQuery.attr() But can get attrbute by document.attrbute. How to solve It?

console.log($("#video01").attr('readyState'));
console.log($("#video01")[0].readyState);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<video id='video01'  src="http://cloud.video.taobao.com/play/u/2554695624/p/1/e/6/t/1/fv/102/28552077.mp4" autoplay=""></video>
Mohammad
  • 21,175
  • 15
  • 55
  • 84

3 Answers3

4

You have to use prop insted attr

console.log($("#video01").prop('readyState'));
console.log($("#video01")[0].readyState);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<video id='video01'  src="http://cloud.video.taobao.com/play/u/2554695624/p/1/e/6/t/1/fv/102/28552077.mp4" autoplay=""></video>
Arkej
  • 2,221
  • 1
  • 14
  • 21
1

readyState is not an attribute. It is a property. So, use

console.log($("#video01").prop('readyState'));
  • What difference about attribute and property? – user6298426 Nov 03 '16 at 01:26
  • _attribute_ is something that you see in your DOM tree, where as _property_ is not visible(or the property value you see in DOM may not be the exact property value). _Property_ changes dynamically, where as _Attributes_ don't( You can manipulate attributes by script, though ). For example, `` box has a _property_ called `value`, this value which change when you modify text inside it. – Rohit Reddy Abbadi Nov 03 '16 at 06:56
-2

Your code don't have "readyState"


console.log($("#video01").attr('readyState'));

readyState must be present on this tag

in above tag src,autoplay,id are attr

Ramesh M
  • 35
  • 1