1

I would like to try to set Attribute in the Console Panel in Chrome.

But without using with the mouse. Example like this: https://developers.google.com/web/updates/2015/08/edit-html-in-the-console-panel

I wish only to write the JS-CODE with command, for example:

document.querySelectorAll(".serial-number").setAttribute("Value","dummy");

In the Console Panel Chrome this function setAttribute is not able. Please is there some alternativ way to write CODE with setting Attribute?

goethe
  • 35
  • 8
  • Why would you be setting an attribute on a collection of elements? I don't know what use a collection has for attributes. –  Mar 14 '18 at 16:02

1 Answers1

1

document.querySelectorAll returns a static nodelist, So need to iterate this collection which will give access to the element.Then setAttribute can be use to set an attribute

var getAllLI = document.querySelectorAll('.demoClass');
getAllLI.forEach(function(item, index) {
  item.setAttribute('value', index)
})
<input class="demoClass">
<input class="demoClass">
<input class="demoClass">
<input class="demoClass">
brk
  • 48,835
  • 10
  • 56
  • 78