1

I have the following form:

<form>
    <input type = "text" id = "test" class = 'test'>
</form>

And the following Javascript code:

<script>
    $(function(){
        $('#test').addClass('thereIsNoSpoon').val('blah');
    })
</script>

When I open the page, and look at Chrome's developer tools -> elements, I can see on the input element, that the class 'thereIsNoSpoon' is visible (Chrome noticed the change, and displays it for me), and in the same moment it does not reflect the change in 'value' attribute. That is, I can see this change on the page, but not in Dev Tools.

I have two questions - why is that and what are the rules behind reflecting/not reflecting changes made to DOM.

konrad_firm
  • 859
  • 1
  • 11
  • 28

1 Answers1

2

jquery $().val('some_value') set the value property of the element.it wont alter the value attribute of the element.you can see value attribut when you use $().attr('value','some_value')

check this SO link

Community
  • 1
  • 1
Pavan Teja
  • 3,192
  • 1
  • 15
  • 22
  • Thank you! I'll have to read about those properties and attributes :) before I thought that this is only Jquery-related (that is, differentiation properties/attributes are jquery's concepts). – konrad_firm Feb 26 '16 at 09:17
  • 1
    Btw if somebody's interested here is the difference between properties/attributes explained very well: http://stackoverflow.com/questions/6003819/properties-and-attributes-in-html – konrad_firm Feb 26 '16 at 09:36