wordpress - What is wrong with my jQuery code? Gives error that it's not a function -
am using in wordpress, tried change $
sign jquery
, did not work too. script:
<script> jquery().ready(function($) { var name = $('#user-submitted-posts-wrapper').data('name'); if ( name != '') $('.usp-title input').eq(0).value(name); }); </script>
and getting error:
$(...).eq(...).value not function
what might problem? trying prefill input field text get. input field has name attribute, no class or id attribute. better use? doing wrong?
because $().value
undefined
(not function).
the value
property belongs htmlinputelement
dom interface, jquery objects don't have property or method name.
jquery objects provide .val()
method set elements' value
property:
$('.usp-title input').eq(0).val(name);
you may , set dom element properties directly retrieving dom element reference jquery object through .get
method:
$('.usp-title input').get(0).value = name; $('.usp-title input')[0].value = name; //shorthand form
Comments
Post a Comment