• I have an image I want to change on click using javascript. The only problem is that the src is a theme mod which is obviously PHP. When I click on the image, the javascript works as expected, but the less than(<), greater than(>) and a few other symbols are changed. Code Below.

    HTML:

    <div id='slide-holder'>
         <img id='sliderjoint' src="<?php echo esc_url(get_theme_mod('selectimage2'));?>"
    </div>

    Javascript:

    function slide(){
    		var pic = document.getElementById('sliderjoint');
    		pic.src = "<?php echo esc_url(get_theme_mod('selectimage2'));?>"
    		console.log(pic.src);
    	}
    
    	var el = document.getElementById('slide-holder');
    	el.addEventListener('click', slide);

    Should I be using AJAX? I don’t really see how that would help me but I just need someone to point me in the right direction.

  • The topic ‘Need help changing image in javascript if src contains PHP’ is closed to new replies.