I have a JavaScript application that applies filters to a live video.
I was wondering how I can display what the current filter is using inner.HTML after the user hits the filter button.
I want to display the current filter (sepia, grayscale etc) in here
<p id="filterName"></p>
Here is my code which changes the filter, I feel I have to put the line of code to display the filter at the end as part of the filter button function.
// CSS filters
//this array will cycle through the filter effects
var index = 0; //the array starts at 0
var filters = ['grayscale', 'sepia', 'saturate', 'hue', 'invert', 'no-filter'];
// this applies the filter to the video feed, takes the class of the video feed
var changeFilter = function () {
var el = document.getElementById('video');
el.className = 'videoClass';
//this will cycle through the filters, once it hits the final filter it will reset
var effect = filters[index++ % filters.length]
if (effect) {
el.classList.add(effect);
console.log(el.classList);
}
}
//when the user presses the filter button it will apply the first filter in the array
document.getElementById('filterButton').addEventListener('click', changeFilter);
Thank you for your time.