jQuery .attr('value', 'new_value') not working?

前端 未结 11 1940
面向向阳花
面向向阳花 2020-12-10 04:56

I am trying to dynamically change the actual HTML value attribute of an input using jQuery. Although using input.attr(\'value\', \'myNewVal\'); wor

11条回答
  •  生来不讨喜
    2020-12-10 05:52

    This may be slightly off topic, but I have found that when I use the .data() function in jQuery, the value is set correctly, but the change isn't reflected in developer tools.

    So,

    $('#element').data('to-update', 'newValue')
    

    In the developer tools (Elements view) still shows the old value.

    But

    $('#element').data('to-update')
    

    returns 'newValue'

提交回复
热议问题