Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Basic function JS not working

I'm looking for load a function while i click on a button. I'm learning JS ...

function changeStyle(){
 var paragraphe = document.getElementById('monParagraphe');
 paragraphe.style.backgroundColor="#000";
}
 
function load(){
 var buttonElt = document.getElementsByTagName('button');
 buttonElt.addEventListener('click', changeStyle)
}
<p id=’monParagraphe’>Lorem ipsum dolor sit amet, consectetur adipisicing
 elit, sed do eiusmod
 tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
 quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
 consequat.
</p>
<button onclick=changeStyle()>Changer le style</button>
 

Answer*

Draft saved
Draft discarded
Cancel

lang-js

AltStyle によって変換されたページ (->オリジナル) /