javascript - jQuery write value into the input field's "value" attribute -
i have input field, input type text:
<input type="text" id="show-val" value=""> <button id="get-val">val</button> on button click it's taking url somewhere else, need place value text field's value attribute.
what is:
$('#get-val').on('click', function(){ var url = 'http://example.com/'; //suppose our grabbed url $('#show-val').val( url ); }); but if inspect input text can see it's not writing url value attribute, it's pasting value text field.
what tried:
$('#get-val').on('click', function(){ var url = 'http://example.com/'; //suppose our grabbed url $('#show-val').prop( 'value', url ); //failed $('#show-val').prop( 'placeholder', url ); //passed }); output is:
<input type="text" id="show-val" value placeholder="http://example.com/"> why failing writing text field's value attribute? how can write actually?
value property $('#show-val').val(url); correct.
however if want modify value attribute use $.fn.attr( attributename, value)
set 1 or more attributes set of matched elements.
code
$('#show-val').attr('value', url);
Comments
Post a Comment