I use jquery .find('input')[0]
which gives me a element like this
<input name='world' value='hello'>
I want to change the value of this textfield. I then find('input')[0].val('')
, but it gave me a type error. Any insight please ?
Use :first
to get the first input.
find('input:first').val('your value here')
or
find('input:eq(0)').val('your value here');
When you do find('input')[0]
, you're actually getting the DOM element and since it's no longer wrapped in a jquery object the .val
property will not work.
If you really want to use your previous code then you could use the native DOM property value
find('input')[0].value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.