Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

change cover photo with javascript

//ui
<form action="" method='post'>
  <img src="https://www.freeiconspng.com/uploads/no-image-icon-13.png" id="coverPreview" alt="">
  <input type="file" id="cover" />
</form>

//css
input{
  display:none;
}

//js
 let coverPreview = document.getElementById('coverPreview');
        let cover = document.getElementById('cover');

        coverPreview.addEventListener('click',_=>cover.click());

        cover.addEventListener("change",_=>{
            let file = cover.files[0];
            let reader = new FileReader();
            reader.onload = function (){
                coverPreview.src = reader.result;
            }
            reader.readAsDataURL(file);
        });
 
PREVIOUS NEXT
Tagged: #change #cover #photo #javascript
ADD COMMENT
Topic
Name
6+6 =