Louis93
Louis93

Reputation: 3923

Why am I unable to grab this input element's default value?

Here is a demonstration of the problem. http://jsfiddle.net/92m4309b/

I have an input element whose value attribute I am trying to read. For some reason, I am unable to read it using jQuery, it returns an empty string.

html

<input type="file" 
   style="display:none;" 
   accept="video/mp4, video/ogv" 
   id="some-random-id" 
   name="some-random-text-input" 
   value="30_sec_Verizon4.mp4"
>

js

$(document).ready(function(){
 console.log($("input").val());
 console.log($("input").attr('value'));
});

What am I doing incorrectly?

Upvotes: 1

Views: 67

Answers (1)

mathf
mathf

Reputation: 316

Use the prop()-method. See the docs for more details: http://api.jquery.com/prop/

$("#some-random-id").prop("defaultValue");

Upvotes: 3

Related Questions