I am curious if it is possible to use javascript to take an existing html-operator, for example
<input id="name">
and convert it to
<input id="name" asdf="fdsa">
Yes, try the following:
document.getElementById("name").setAttribute("user-attr","Hello")
Pure Vanilla Javascript!
You can also use the dataset property to store data in an element.
document.getElementById("name").dataset.someDataAttr = 'mydata';
This will result in an attribute named "data-some-data-attr".
First enter the dom element:
var element = document.getElementById("name");
Then set the attribute
element.setAttribute("asdf", "fdsa");
If you are using jQuery
$("#name").addr("asdf", "fdsa");
you can do it using jquery also
$('#name').attr('asdf','fdsa');
Yes it is possible.
Vanilla JS:
document.getElementById('name').setAttribute('asdf','fdsa');
JQuery
$("#name").attr("asdf","fdsa");
Source: https://habr.com/ru/post/1484339/More articles:Spinner dropUP instead of dropDOWN android - androidFacebook Post Comment Using Api - ruby-on-railsKeep line break from Textarea - html`git add *` suggests a fatal error - gitButton "Refresh game", "Pause" in the list - android-listviewWhy are there unwanted duplicate and extra columns in Asp: GridView? - c #Bash script in tail -f with colored lines - linuxCustom pointer in graph structure - graphHow to set marker on google map using javascript - javascriptHow to assign null to structure for pinvoke call? - c #All Articles