So I have some <select>
elements and each of its possible options have a price inside span. I loop through all select tags and I need to get the value of the span of the selected option for each of them. So this is my code
<select class="form-control config-option" id="s{{ $availableCategory->index}}">
<option>{{ $availableCategory->default_option }}</option>
@foreach($availableOptions as $availableOption)
@if($availableOption->category->name == $availableCategory->name)
<option>({{ $availableOption->code }}) {{ $availableOption->name }} <span class="option-price">({{ $currency == 'EUR' ? 'EUR' : 'USD'}} {{ $availableOption->price }})</span></option>
@endif
@endforeach
</select>
I tried to access it via the find()
function of jQuery by class and by tag name but I fail to do so.
$('.config-option').each(function() {
var currentElement = $(this);
var optionPrice = currentElement.find('.option-price');
console.log(optionPrice);
});
If I console log optionPrice.val()
I get undefined. So how can I access this span? Is there a better way to do it? A solution using plain JavaScript would do as well.