I have an error in the code, tell me what is wrong with the variable?

function setImage(elementId, strImage) { var imageElem = getElement(elementId); if (!imageElem) return; imageElem.src = strImage; } function iSwap(imgID, newImg) { newImgPath = "" + newImg; setImage(imgID, newImgPath); } 

The error console swears at this: ReferenceError: getElement is not defined. Error directly in line:

 var imageElem = getElement( elementId ); 
  • apparently function getElement not defined - Specter
  • And I think that elementId is not defined, but I don’t know how. - oldzas

1 answer 1

The getElement function is not defined, strictly speaking it does not even know that it is a function. Accordingly, you either need to describe it somewhere, or use the methods from document - document.getElementById() , document.getElementsByTagName() and document.getElementsByName() .
How to use can be read here .