1

Is there any way to put img tag in the text of a html option? For example i need something like this :

<select>
  <option value="1"> Text1<img src="foto.png"> </option>
  <option value="2"> Text2<img src="foto.png"> </option>
</select>
Fotis_zzz
  • 150
  • 1
  • 10

4 Answers4

2

An option cannot have any children elements, including img.

The HTML5 <option> spec says the following (Emphasis mine):

If the first argument is not the empty string, the new object must have as its only child a Text node whose data is the value of that argument. Otherwise, it must have no children.

Mooseman
  • 18,763
  • 14
  • 70
  • 93
0

Only FireFox browser support Background images on Select options:

test.html

<select id="test_select">
  <option>test1</option>
  <option>test2</option>
</select>  

style.css

select#test_select option[value="test1"]   { background-image:url(test1.png);   }
select#test_select option[value="test2"] { background-image:url(test2.png); }

Or you can use Jquery Selector to show Images.. http://api.jqueryui.com/selectable/

AJ101
  • 69
  • 1
  • 8
0

We can add a image inside option tag by jQuery and only in firefox!

Look here: http://jsfiddle.net/L8s6spp4/1/

Html:

This code Only works in Firefox.
<br/>
<select id="myselect">
  <option value="_none"> - Select One - </option>
  <option value="asterisk">asterisk</option>
  <option value="plus">plus</option>
  <option value="euro">euro</option>
</select>

Jquery:

(function($) {
  $(document).ready(function() {
    $('#myselect option').each(function() {
      $(this).html('<img src="http://jsfiddle.net/img/logo.png">' + $(this).html());
    })
  });
})(jQuery);
0

You can use fontAwesome, to show some 'img'. For example, using &#xF046 can show a checkbox image. It's better than nothing.

Zhou Hongbo
  • 1,297
  • 13
  • 25