I am trying to get text before '-' in a string in javascrip e.g I would like to get February 27, 2021 11:30 from February 27, 2021 11:30 - 12.30.
Below is the code snippet but I get the error: Cannot read property 'split' of undefined.
console.log(
new Intl.DateTimeFormat('en-US', {
weekday: 'long'
}).format(
new Date(
$("#am-events-booking").find('am-event-sub-info:eq(1)').innerHTML.split(' - ')[0] // only interested in the "February 27, 2021 11:30 am" part
)
)
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="#am-events-booking">
<div class="am-event-info">
<div class="am-event-sub-info">
<div class="am-event-sub-info-capacity"><img src=""> Capacity: 0 / 100</div>
<!---->
</div>
<div class="am-event-sub-info">
<div><img src="">February 27th, 2021 11:30 am - 1:00 pm</div>
</div>
</div>
</div>
.innerHTML, but rather.val().