Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

changing photo with js

//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);
        });
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #changing #photo #js
ADD COMMENT
Topic
Name
3+6 =