Загрузка...

Как сделать так, чтоб при нажатии одной кнопки вторая пропадала?

Тема в разделе Frontend создана пользователем fafafafafafafa 22 авг 2021. 181 просмотр

  1. fafafafafafafa
    fafafafafafafa Автор темы 22 авг 2021 3 27 июл 2021
    Есть 2 кнопки, как сделать чтоб когда нажимаю на одну, вторая пропадала, и наоборот?
    Код

    window.addEventListener('load', () => {
    addButton('RUN w/o max mode', autoclck)
    });

    function addButton(text, onclick, cssObj) {
    cssObj = cssObj || {position: 'absolute', bottom: '95.5%', left:'75%', background: 'purple', color: 'white', width: '140px', height: '25px', 'z-index': 3}
    let button = document.createElement('button'), btnStyle = button.style
    document.body.appendChild(button)
    button.innerHTML = text
    button.onclick = onclick;
    button.addEventListener('click', () => {
    button.style.backgroundColor ='green';
    });
    Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key])
    return button
    }

    window.addEventListener('load', () => {
    bddButton('RUN w/ max mode', automax)
    });

    function bddButton(text, onclick, cssObj) {
    cssObj = cssObj || {position: 'absolute', bottom: '95.5%', left:'15%', background: 'purple', color: 'white', width: '140px', height: '25px', 'z-index': 3}
    let button = document.createElement('button'), btnStyle = button.style
    document.body.appendChild(button)
    button.innerHTML = text
    button.onclick = onclick;
    button.addEventListener('click', () => {
    button.style.backgroundColor ='green';
    });
    Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key])
    return button
    }
     
  2. de9x
    de9x 22 авг 2021 Frontend developer 141 3 янв 2019
  3. fafafafafafafa
    fafafafafafafa Автор темы 22 авг 2021 3 27 июл 2021
    de9x, Спасибо за ответ, но я сделал чуток по другому, я присвоил обоим элементам айди
    Код
    button.id = "zzz"
    , и после этого в эвент клик добавил вот это
    Код
    document.getElementById('zzz').hidden = true;
     
Загрузка...
Top