I have a dropdown on my website where users get to select the payment method. I want an image to appear to the right of the option selected by the user.
I have tried using the below code. This code was taken from this thread: jQuery onchange/onfocus select box to display an image?
JS fiddle link: https://jsfiddle.net/lindychen/102fmpu8/1/
HTML code
<select name="form_fields[field_5]" id="form-field-field_5" class="elementor-field-textual elementor-size-sm" required="required" aria-required="true">
<option value=""></option>
<option value="https://i.imgur.com/4vRsaJa.png">Paypal</option>
<option value="https://i.imgur.com/ZPC09qT.png">Credit Card</option>
</select>
</div>
Jquery code
$("form-field-field_5").change(function() {
var src = $(this).val();
$("#form-field-field_5").html(src ? "<img src='" + src + "'>" : "");
});
});
This is the expected result:
However, currently, I do not see the pictures appearing to the right of the text. Unfortunately, I am not able to change the HTML code used. Thank you.