I have an image thumbnail set in option
of select
.
I would like the script to automatically insert the caption, for each of these images in select
, based on the attribute in> title
.
The example of what I've done:
window.onload = function(){
var opt = document.getElementById('lista').getElementsByTagName('option');
var txt = document.getElementById('lista').getElementsByTagName('b');
for (var n=0; n < txt.length; n++) {
for (var i=0; i < opt.length; i++) {
txt[n].getElementsByTagName('b')[0].innerHTML = opt[i].getElementsByTagName('option')[0].title;
}
}
}
body {
background-color: whitesmoke;
}
option {
font-size: 12pt;
color: white;
padding: 10 10 10 10;
margin: 0 auto;
background-repeat: no-repeat;
background-size: 100px;
height: 50px;
}
option:hover {
background-color: whitesmoke;
border-right: 2px solid tomato;
cursor: pointer;
size: 150%;
}
.bloc select {
width:450px;
height:100%;
padding:30px;
background-color: white;
float: right;
border:none;
margin: 0px -20px 0px 0px;
}
.bloc {
overflow: hidden;
}
<div class="bloc">
<select id="lista" size="3">
<option style="background-image: url(https://sites.google.com/site/mplayerplugin/repositorio/big_buck_bunny.jpg);" title="Big Buck Bunny">Big Buck Bunny</option> <b></b>
<option style="background-image: url(https://sites.google.com/site/mplayerplugin/repositorio/madagascar_2.jpg);" title="Madagascar 2">Madagascar 2</option> <b></b>
<option style="background-image: url(https://sites.google.com/site/mplayerplugin/repositorio/procurando_dory.jpg);" title="Procurando Dory">Procurando Dory</option> <b></b>
</select>
<div>
Note that if you use the attribute option
of the text
then it will be over the image - then I saw that it would be necessary to invest efforts in working with the% since the same is hidden, all you have to do is look for a way to get your content and between another text tag . As an example, option
, title
, span
, b
, p
etc ...
, Although the console did not acknowledge any error , it still did not bring me any results.