alexa

Interchnage the children of two divs using a button in js ?

Interchnage the children of two divs using a button in js ?

Do you mean smth like this?

 

 function handleButtonClicked(type) {

  if (type === 'main') {
    const mainElement = document.getElementById('subele1')
    mainElement.innerHTML += '!'
  }

  if (type === 'sub') {
    const mainElement = document.getElementById('subele2')
    mainElement.innerHTML += '?'
  }
}
 <div id="mainWindow">
  <div id="subele1">main Window!</div>
</div>

<div id="subWindow">
  <div id="subele2">sub Window?</div>
</div>

<button id='main' onclick={handleButtonClicked('main')}>main</button>
<button id='sub' onclick={handleButtonClicked('sub')}>sub</button>

217 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry