Próbowałem tak:
$('#option_items').click(function(){ $this = $(this); var a = document.getElementById($this).getAttribute('path'); $('#img_itm').html('<img src="'+ a +'"/>'); });
Lecz wartość null.
$('#option_items').click(function(){ $this = $(this); var a = document.getElementById($this).getAttribute('path'); $('#img_itm').html('<img src="'+ a +'"/>'); });
<select id="nazwa_selecta"> </select> <script> document.getElementById("nazwa_selecta").onchange = obsluga_option; function obsluga_option(){ var aktualny = document.getElementById("nazwa_selecta").options[document.getElementById("nazwa_selecta").selectedIndex].getAttribute("path"); document.getElementById("obrazek").innerHTML = "<img src=\""+aktualny+"\"/>"; } </script>
<form> <select id="images"> </select> </form> <script> var $select, $img_container; $select = $( "#images" ); $img_container = $('#img_itm'); $select.change(function() { show_selected_image(this); }); $(document).ready(function () { show_selected_image($select); }); function show_selected_image (list) { var img_src; img_src = $(list).find(':selected').attr('data-path'); $img_container.html('<img src="' + img_src + '"/>'); } </script>