UPDATED ANSWER:
After user Rory McCrossan pointed out that this wouldn't work on Firefox, I was inspired to try to find a solution that would, that would also be moderately more accessible to screen-reader and keyboard users. I came up with the following:
const enableSelect = () => {
const selectWrapper = $("#select-wrapper")
$(selectWrapper).removeAttr('aria-label');
$(selectWrapper).find("select")
.removeAttr('disabled', false)
.toggleClass('.disable-pointer')
.focus();
};
$(document).ready(() => {
$("#select-wrapper")
.on('click', enableSelect)
.on('keypress', (e) => {
if (e.key === 'Enter') {
enableSelect();
}
});
});
.disable-pointer {
pointer-events: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input/>
<div id="select-wrapper" tabIndex="0" aria-label="click here to enable options">
<select class="disable-pointer" id="area" disabled name="area" required>
<option value="Adabar Thana">Adabar Thana</option>
<option value="Azampur">Azampur</option>
<option value="Badda Thana">Badda Thana</option>
<option value="Bangsal Thana">Bangsal Thana</option>
</select>
</div>
This leverages the pointer-events: none
solution recommended in this post. In addition, make the wrapper focusable, and give it a label via ARIA. Upon click or keypress of enter, we remove the label, enable the select and focus it. Depending on your intentions, it would probably be wise to also remove the tabIndex
from the wrapper at this junction, and also probably give it a cleaner focus treatment that more emulates a button.
As I commented on your original post, this still may be inadvisable from an accessibility point of view-- I'd recommend testing with some screen readers, the keyboard, and checking browser accessibility trees to confirm everything is usable by those who might not be using a mouse and screen.
Original Answer Below
While the disabled
<select>
itself might not accept click events, you could always wrap it in a wrapper that can register the event:
$(document).ready(function() {
$("#select-wrapper").dblclick(function() {
$(this).find("select").removeAttr('disabled', false);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="select-wrapper">
<select id="area" disabled name="area" required>
<option value="Adabar Thana">Adabar Thana</option>
<option value="Azampur">Azampur</option>
<option value="Badda Thana">Badda Thana</option>
<option value="Bangsal Thana">Bangsal Thana</option>
</select>
</div>