S
S
Senseich2017-10-18 17:34:34
HTML
Senseich, 2017-10-18 17:34:34

Why does setAttribute() throw an Uncaught TypeError: name.setAttribute is not a function?

I want to add an attribute to an element

oninvalid="this.setCustomValidity('Введите своё имя')"

<script>
var name = document.getElementById("MyName");
name.setAttribute("oninvalid", "this.setCustomValidity('Введите своё имя')");	
</script>

In the console it gives an error Uncaught TypeError: name.setAttribute is not a function?
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Michael, 2019-07-17
@xonar

Background with background-size, background-position
A block that runs over the background, so just margin-top -Npx or move it a little through position relative if it is somehow above the flow in the design,
But certainly not through absolute

D
Dmitry Derepko, 2019-07-17
@xEpozZ

Create a menu after this banner and indent it with either margin or position: absolute.
Better second option

S
Stalker_RED, 2017-10-18
@Stalker_RED

document.querySelector('#MyName').addEventListener('invalid', function(){
  this.setCustomValidity('Введите своё имя')
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question