I am trying to append a different id to options within select element. I can do this with images, but dont know how to do it with ID's
Example: for images we use:
$(document).ready(function() {
$("#selectanimage").change(function() {
var src = $(this).val();
$("#masterPreview").html(src ? "<img src='" + src + "'>" : "");
});
});
The typical select would be:
<select id="selectanimage" name="selectanimage" style="width: 474px;" class="required">
<option value="null">--- Select your Image ... ---</option>
<option value="share/images/125x125blk.png">125px x 125px Black Background</option>
<option value="share/images/125x125wht.png">125px x 125px White Background</option>
<option value="share/images/180x100blk.png">180px x 100px Black Background</option>
</select>
What I want to do is .. change value in options to differenct class or id, and then get the js to switch accordingly.
So option value="apple"
option value="foo"
Im not sure if thats 100% clear lol
The objective is that the Div id masterpreview can contain the new class or id element of the option.
ie.
on click of option ( say someone clicked foo )
Then we would generate:
<div id="masterPreview">
<div class="foo"></div>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…