1
I have a thumbnail set of images on option
of select
.
I would like the script automatically enter the caption for each of these images in the select
, based on attribute title
of tag option
.
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>
Please note that if you use attribute text
of option
then it will stand on the image - then I saw that it would be necessary to invest efforts in working with the attribute title
, since it is hidden, just search for a way to pick up its content and between another text tag. As an example: span
, b
, p
, strong
, small
etc....
The script, although the console does not accuse any error, hasn’t brought me any results yet.
I imagine you could use a LI list to do this instead of SELECT, because SELECT is not quite the best choice to do such a thing. Also vc cannot put elements between OPTION pq the HTML will not display.
– Sam
Yes, that would be an option. Select the width of the images and put a list next to it displaying the names.
– Sam
@So how did I ever manage to capture the
title
and play within thediv
I will prepare an answer for this topic. It will be for future research and consultation.– Diego Henrique
I had thought about it too, but I didn’t know that OPTION could have pseudo-elements :D... but see that if the title of the film is long, the text disappears on the right ;/
– Sam
I saw it, but clicking the <p> does not select the option.
– Sam
@dvd It is a detail that I will edit, as I am still framed a coherent explanation to the context, and leave a hint for
loop
create the elementp
dynamically since it is not known how much item I can add to theselect
, not having the need to keep inserting tagsp
manually in thecontainer
.– Diego Henrique