So I am creating a custom component based on <ul><li>
but looking more like a <select><option>
and when clicking on it I want its foreground/background to be set to whatever is the default selection colour on the users system, by adding something to css for that particular component
Currently it is just hardcoded to a version of blue which would only be right for a specific browser on particular OS
.delete_criteria li.selected {
background-color: #3399FF;
color: white;
}
If I don't add the above CSS then there is no visible change when you select it. What I want to do is set to to default as this pseudo code will demonstrate
.delete_criteria li.selected {
background-color: default-selection-background-colour;
color: default-selection-foreground-colour;
}
but I don't know what to replace default-selection-background-colour and default-selection-foreground-colour with
Fuller example showing the html and javscript:
<div class="delete_criteria">
<ul>
<li>
<div>
<label>
Audio Format
</label>
<input name="AUDIOFORMAT" id="AUDIOFORMAT" value="AUDIOFORMAT" hidden="hidden" type="text">
</div>
</li>
<li>
<div>
<label>
Bitrate
</label>
<input name="BITRATE" id="BITRATE" value="BITRATE" hidden="hidden" type="text">
</div>
</li>
<li>
<div>
<label>
Track Length
</label>
<input name="TRACKLENGTH" id="TRACKLENGTH" value="TRACKLENGTH" hidden="hidden" type="text">
</div>
</li>
<li>
<div>
<label>
Filename
</label>
<input name="FILENAME" id="FILENAME" value="FILENAME" hidden="hidden" type="text">
</div>
</li>
<li>
<div>
<label>
File Creation Date
</label>
<input name="FILE_CREATION_DATE" id="FILE_CREATION_DATE" value="FILE_CREATION_DATE" hidden="hidden" type="text">
</div>
</li>
<li>
<div>
<label>
File Modified Date
</label>
<input name="FILE_MODIFIED_DATE" id="FILE_MODIFIED_DATE" value="FILE_MODIFIED_DATE" hidden="hidden" type="text">
</div>
</li>
</ul>
<button id="up" type="button">
Up
</button>
<button id="down" type="button">
Down
</button>
// enable moving an element up
document.getElementById('up').addEventListener('click', () => {
var li = document.querySelector('li.selected');
if (li.previousElementSibling !== null) {
li.parentNode.insertBefore(li, li.previousElementSibling);
}
});
// enable moving an element down
document.getElementById('down').addEventListener('click', () => {
var li = document.querySelector('li.selected');
if (li.nextElementSibling !== null) {
li.parentNode.insertBefore(li, li.nextElementSibling.nextElementSibling);
}
});
</script>
</div>
</td>
</tr>
</table>
<div>
.delete_criteria ul {
padding-left: 0;
width: 20em;
list-style-type: none;
border: 1px solid darkgray;
vertical-align:top;
}
.delete_criteria li {
padding: 2px 4px;
}
.delete_criteria li.selected {
background-color: #3399FF;
color: white;
}
I have read the question below but it only shows you how to set the value to a hardcoded value irrespective of users situation.
What is the browser-default background color when selecting text?