Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to pass data from javascript obj to html tag

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #284186
    Andrew_88
    Participant

    I have this javascript object

    var array = [ {width:”50vw”, imageUrl:”url50vw.jpg”} , {width:”100vw”, imageUrl:”url100vw.jpg”} ].

    I need to put this data (via javascript) ,like srcset attribute, into an img html tag like this

    But I can’t find a way. Can you help me?

    #284187
    Shikkediel
    Participant

    I’m assuming something like this:

    var image = document.getElementById('myimage');
    
    image.src = array[0]['imageUrl'];
    image.style.width = array[0]['width'];
    

    Or:

    image.src = array[0].imageUrl;
    image.style.width = array[0].width;
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.