I want to change through style = "background-color:" directly, without causing

document.getElementById(this.id).style.backgroundColor = "#ffffff"; 

and writing it directly in the context of this, in principle, it works, that is, for example, you can do so

 <input type="text" id="old_id" style="background-color: #ffb3b3" onkeyup="input_fn(this)"> 

and then do

 function input_fn() {this.id = "new_id"} 

and everything works fine in chrome, the id of the element will change the value, but here in the VERY long list of this I haven’t found anything like style , can anyone tell me where it’s hidden there ??

  • so I did not understand, in the end you want to change the id or style? What is this function () {this.id = "new_id"} and where is it called? why do so document.getElementById(this.id) if you already have this ? - Grundy
  • I want to change the style, I just gave an example that it works, until I met this way of working with DOM elements and I don’t know how valid it is, there should be no technical problems - pnp2000

1 answer 1

 function input_fn(elem){ elem.style.backgroundColor = "#ffffff"; } 
 <input type="text" id="old_id" style="background-color: #ffb3b3" onkeyup="input_fn(this)"> 

  • thanks, it works, it's strange that in the console.dir of this object does not show the style attribute - pnp2000
  • Perkovec we have with you just karma in action :) - pnp2000
  • @ vnn198 did not understand what? - Perkovec
  • Well, if you remember, I once helped you with the launch of the executable in the node :) - pnp2000