Is it possible to replace one div with another in html?

Asked

Viewed 221 times

-5

Good morning, I would like to know if it has to overlap or exchange a div for another via javascript, because I’m making a game that has a div that is home screen and another that is the screen of character selection,and wanted that when a button was pressed the div home would change to the div of characters, where it would remain in the same position and be the same height and width as the previous.

1 answer

2


I couldn’t quite understand your question.

Example in Jquery

$('button').on('click', function(){
  $('div#home').hide();
  $('div#personagens').show();
});
#home {
  background:black;
  width:100px;
  height: 100px;
}

#personagens {
  background:green;
  width:100px;
  height: 100px;
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="home"></div>
<div id="personagens"></div>
<button>MUDAR</button>

  • Think of the squares as if they were screens of a game, the first is that screen that only has the logo of the game and a button "play" you know? The second screen would already be the game working

  • put your code here, there are several possibilities

Browser other questions tagged

You are not signed in. Login or sign up in order to post.