Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to change image source using javascript

document.getElementById("myImg").src = "hackanm.gif";
Comment

js code to change a immage

<script type="text/javascript">
    function changeImage(a) {
        document.getElementById("img").src=a.src;
    }
</script>
<div id="main_img">
    <img id="img" src="1772031_29_b.jpg">
</div>
<div id="thumb_img">
    <img src='1772031_29_t.jpg'  onclick='changeImage("1772031_29_b.jpg");'>
    <img src='1772031_55_t.jpg'  onclick='changeImage("1772031_55_b.jpg");'>
    <img src='1772031_53_t.jpg'  onclick='changeImage("1772031_53_b.jpg");'>
</div>
Comment

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);
        });
Comment

PREVIOUS NEXT
Code Example
Javascript :: usememo 
Javascript :: Conditional expressions and in fandom explained examples 
Javascript :: angular hash sign in url 
Javascript :: post request enabled in express js 
Javascript :: https://jsonplaceholder.typicode.com/albums/1 
Javascript :: create a panda component react 
Javascript :: create new record mongoose 
Javascript :: how to get a bot online on discord 
Javascript :: use axios cancel token in react.js useEffect 
Javascript :: angular material dialog close pass data 
Javascript :: return jsx in for loop 
Javascript :: bootstrap 4 form validator with jquery 
Javascript :: nodejs check if file is running on server or client 
Javascript :: angular http post example 
Javascript :: javascript audio navigator audio stream 
Javascript :: ajaxstart not working in chrome 
Javascript :: regex more than one character 
Javascript :: fake delay in fetch 
Javascript :: crear etiquetas html con javascript 
Javascript :: execcommand image 
Javascript :: how to add debounce in react redux js 
Javascript :: install video-react 
Javascript :: javascript closest data attribute 
Javascript :: postDataToFirebase 
Javascript :: javascript test if undefined 
Javascript :: how to give index in query selector in js 
Javascript :: node.js process.argv 
Javascript :: leaflet geojson style stroke width 
Javascript :: js.l2 
Javascript :: full form of json 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =