Using Javascript and CSS to display or hide HTML element

Wednesday, October 31, 2018 / mcchu28


Possibly save 1 hour of your time: Often you may need to display or hide a certain element based on some condition.

function displayHtmlElement() {
    if (condition !== "") {
        $(element1).css('display', 'none');
        $(element2).css('display', 'block');
    } else {
        $(element1).css('display', 'block');
        $(element2).css('display', 'none');
    }
}