skip to Main Content

you need to make it so that when you press the change theme button, the photos change

I don’t know how to do it, there are no suitable guides

helphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelp

2

Answers


  1. basically you have to add a onclick function on the tag and then use javascript to change the src value.
    Code is given below
    HTML

    <p onclick=edit()>Click me</p>
    

    JS

     function edit()
    {   
        var img = document.getdocumentbyid('documentid');
        img.src= 'your desired thing'
    
        }
    

    If want to change multiple photos then
    src should be named like photo1 photo2 so on and the code should be

    let i=0
    function edit(){
    var img = document.getdocumentbyid('documentid');
    img.src= 'photo${i}'
    i++
    

    }

    not generated, but typed statically

    Login or Signup to reply.
  2. Suppousing you have buttons and image like this:

    <button onclick="changeTheme('dark')">Dark Theme</button>
    <button onclick="changeTheme('cool')">Cool Theme</button>
    <img id="theImage" src="/images/defaultTheme/image.jpg">
    

    You could do something like this in javascript to change the src image according to the chosen theme:

    function changeTheme(themeName){
        const img = document.getElementById("theImage");
        img.src= `/images/${themeName}Theme/image.jpg`
    }
    

    This way you can add as many buttons as themes youu have, and each one will call changeTheme function on their own click event, passing themeName to it, making the src of the image tag change to the desired theme image.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search