Skip to content Skip to sidebar Skip to footer

QuerySelector Set Text Value

I have this loop which should set the value to none and update the placeholder. When I log the node it works fine but the value and placeholder are not u

Solution 1:

You shouldn't parse an object just use it :

var data= {"password":"password","username":"xhinii"};

for(var prop in data) {
    document.querySelector('input[name = "' + prop + '"]').value = prop; 
    document.querySelector('input[name = "' + prop + '"]').setAttribute('placeholder', data[prop])
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name='password' />
<input name='username' />

Post a Comment for "QuerySelector Set Text Value"