Jump to content
man5

Is it possible to replace a div or button on click?

Recommended Posts

Say I have button 1 and I want to replace it with button2 on click.  How would I do that?

<button id="button1">butto 1</button> 
<button id="button2">butto 2</button> 

Share this post


Link to post
Share on other sites

How exactly do you want to replace it? You want to put the value from the one button to the other, or...?

Share this post


Link to post
Share on other sites
I have an alternate way:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<button class="button1">button 1</button> 
<button class="button2">button 2</button> 

<script>
	
$(document).ready(function(){
	
    $(".button1").click(function(){
		
        $(".button1").hide();
		$(".button2").show();
        });
		
		$(".button2").click(function(){
		
        $(".button2").hide();
		$(".button1").show();
       });
    });
	
	
</script>

</form>
</body>
</html>

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.