#How do you pass a javascript variable to this?

14 messages · Page 1 of 1 (latest)

dusky knoll
#

so i have an <img> element in HTML and i want to pass a javascript variable through the src=" "

how would i go about doing that?

vestal shore
#

You'd find the element by giving it an id, and then you could modifying the source attribute that way.

#
document.getElementById("img_id").src = "awesome.png";
dusky knoll
vestal shore
#

If you're using jquery, yeah

#

that should work.

dusky knoll
# vestal shore If you're using jquery, yeah
$('#pfp').on('input', function() {
            var data = $("#pfp").val();
            $("#pPfp").src = data;
        })
```it doesnt seem to recognise .src, atleast i think

"pfp" is the id of the file input
"pPfp" is the id of the img element
#

i want it so that when the user selects an image that image shows up

dusky knoll
mild viper
dusky knoll
mild viper
#

find a safer way

#

I guess

jolly salmon