I have an input like this:
<input id="xx" data-p="">
How can i change the value inside data-p using javascript?
I have an input like this:
<input id="xx" data-p="">
How can i change the value inside data-p using javascript?
You can use querySelctor() to select input and setAttribute() to set value of data-p.
document.querySelector('input[data-p]').setAttribute('data-p', 'something')
document.querySelector('input[data-p]').setAttribute('data-p', 'something')
<input data-p="">
You can also use HTMLElement.dataset so it will be
document.querySelector('input[data-p]').dataset.p = 'something'
document.querySelector('input[data-p]').dataset.p = 'something'
<input data-p="">
using below code you can do that.
document.getElementById("TextboxID").setAttribute('data-p', 'something')
or
document.getElementById("TextboxID").attributes["data-p"] = "Value";
What you want to change is called Data Attributes.
To change it use .dataset.p = 'new val'