Skip to content

image or src property in CardMedia is not working when changing using getElementById() #11702

@worstkiller

Description

@worstkiller

Hi guys first of all thanks for making this wonderful library. I am new to React and has started my projects using this framework.
While using i had a small problem related to CardMedia, when ever i am trying to change the image or src property using document.getElementById() or something related to this, it's not changing anything. Here is code if i am doing it wrong.

<CardMedia id="testImage"
          className={classes.media}
          image="/static/images/cards/contemplative-reptile.jpg"
          title="Contemplative Reptile"
        />

//javascript code for manipulating image source
const testUrl = "https://www.fatbit.com/fab/wp-content/uploads/2015/12/material-design-3.jpg";
document.getElementById("testImage").src = testUrl;
console.log(document.getElementById("testImage"));

//here is console output 
<div class="MuiCardMedia-root-7129 SimpleMediaCard-media-7100" id="testImage" title="Contemplative Reptile" style="background-image: url("/static/images/cards/contemplative-reptile.jpg");"></div>

My Environment

Tech Version
Material-UI v1.2.0
React 16.4.0
browser chrome 66

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions