How I can implement that if I click button then it loads data where is select option and then it auto selects that option. But it cant select by value=""
. It should select by text.
Example my button is:
<button class="roomBtn" data-title="Studio Exclusive">Book now</button>
And if I click that button it loads data in modal and there is select option field where is multiple different options but cant select option by value. It has to be select by text what contains data-title=""
value.
<select class="room-select">
<option value>Select product</option>
<option value="12">500€ - Studio Prime</option>
<option value="13">750€ - Studio Exclusive</option>
</select>
So it has to select that option Studio Exclusive because it contains that title.
I've tried this but it didn't work:
jQuery(document).ready(function($) {
let buttonText = $(".roomBtn").attr("data-title");
$(".room-select option:contains('" + buttonText + "')")
.filter(function(i){
console.log($(this).text());
return $(this).text() === buttonText;
})
.attr("selected", true)
});