Set a link’s href value to the href value of another link

Change the href value of the layout header’s “Book Now” link to match the href value of the unit.php page’s “Check Availability” link

JavaScript:

// Change the href value of the layout header's "Book Now" link to match the href value of the unit.php page's "Check Availability" link
// AW 2022-03-11
const unitBookNow = () => {
    const url = window.location.href
    const page = url.substring(url.lastIndexOf('/'))

    if (page.indexOf('unit?id=') >= 0) {
        const bookingButton = document.querySelector('.booking-button')
        const bookingButtonUnit = document.querySelector('.booking-button-unit')
        const unitUrl = bookingButtonUnit.href
        bookingButton.href = unitUrl
    }
}
unitBookNow()