I have a script that transforms selected option from the dropdown list into a link.
Each dropdown is contained inside <li> – and there can be unlimited duplicates added through my script, so it makes kind of difficult to give each <li> an id-selector.
HTML:
<ul class="mylist">
<li>
<select>
<option value="http://google.com">Google</option>
<option value="http://twitter.com">Twitter</option>
</select>
</li>
</ul>
Part of my script that is responsible for adding more duplicates and transforming dropdown list into link.
$(document).keydown(function (e) {
var key = e.which;
if(key == 107) {
$('.mylist').append("<li><select><option value='http://google.com'>Google</option><option value='http://twitter.com'>Twitter</option></select></li>");
}
});
$("button").click(function () {
var which = $("select").val();
var text = $('select option:selected').html();
$("select").replaceWith("<a href='" + which + "'>" + text + "</a>");
});
I need to change my script so it transforms EACH dropdown <select> into EACH selected value, because now it transforms EVERY dropdown into the first dropdown's value. How do I do that if I have no id-selectors, since unlimited duplicates may be added?