css - can I post images in a JavaScript array -


i asking series of questions of user. @ end of question system shows bunch of items. next each item want add picture item.

can put image array?

i have searched this, of results complicated me understand.

i wondering if can put pictures in css , have javascript change <div>'s id can post picture , item?

this thought work:

var blue = ["question1button1" + "img/ads.jpg"];

you use classes:

function setbgclass(arg1) {    var el = document.getelementbyid("bg-container");    var clname = 'background-' + arg1;    el.classname = '';    el.classlist.add(clname);  }
#bg-container {    width: 200px;    height: 200px;  }    .background-1 {    background: url("https://avatars0.githubusercontent.com/u/82592?v=4&s=200");  }    .background-2 {    background: url("https://pbs.twimg.com/profile_images/794277147846340608/tmfi-dro.jpg");  }
<div id="bg-container"></div>  <button onclick="setbgclass(1)">background 1</button>  <button onclick="setbgclass(2)">background 2</button>

or edit source attribute of image tag:

function setbg(arg1) {    var el = document.getelementbyid("bg");    el.setattribute('src', arg1);  }
<img id="bg" src=""/>  <button onclick="setbg('https://pbs.twimg.com/profile_images/794277147846340608/tmfi-dro.jpg')">background 1</button>  <button onclick="setbg('https://avatars0.githubusercontent.com/u/82592?v=4&s=200')">background 2</button>

edit non-jquery solution grab elements images class:

you can use document.queryselector('.images') , elements have class images array or if want support older browsers use document.getelementsbyclassname('images')


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -