Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:55:20+00:00 2026-06-07T19:55:20+00:00

This is my buttons: <button id=add>Add</button> <button id=remove>Remove</button> this is my JavaScript code: <script

  • 0

This is my buttons:

<button id="add">Add</button>
<button id="remove">Remove</button>

this is my JavaScript code:

<script type="text/javascript">
    $(document).ready(function(){   
        /*** Add attribute ***/
        $("#add").click(function(){
            $("#page_navigation1").attr("id","page_navigation1");
        });     
        /*** Remove attribute ***/
        $("#remove").click(function(){
            $("#page_navigation1").removeAttr("id");
        });     
    });
</script>

and this is my html code:

<div id="page_navigation1">next</div>

My problem is, when I click on Remove button everything is fine and ID will be removed,
but after click on remove button, when I click on Add button, code is not working and nothing happens!

I need to add and remove ID whith this code, but I can just Remove ID, I cant add ID. I need some help for this, and one more thing,

How I can add CSS style for button when button is Active?
like this, when I click on Remove button, I want change button background to red. I need to add css class for add and remove when buttons are active! and I dont know how!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:55:21+00:00Added an answer on June 7, 2026 at 7:55 pm

    It’s because you’ve removed the id which is how you’re finding the element. This line of code is trying to add id="page_navigation1" to an element with the id named page_navigation1, but it doesn’t exist (because you deleted the attribute):

    $("#page_navigation1").attr("id","page_navigation1");
    

    Demo: jsFiddle

    If you want to add and remove a class that makes your <div> red use:

    $( '#page_navigation1' ).addClass( 'red-class' );
    

    And:

    $( '#page_navigation1' ).removeClass( 'red-class' );
    

    Where red-class is:

    .red-class {
        background-color: red;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code: <script type='text/javascript'> $(document).ready(function () { //Check if url hash value
My code is as follows: <script> $(document).ready(function() { var tagCounter=0; $(#tag-add-button).click(function () { var
This code works anywhere else.. form load, button click, etc. But when I add
Hey I have my code as follows at the moment <script type=text/javascript> var activeTabId
I'm starting to learn Backbone with this simple example: <div id=counter>unkown</div> <button id=add-button>ADD</button> (function($){
i add this script to my page it is a poll contain a button
I've got a button on my page in code behind I do this: btnSaveLineItems.Style.Add(display,
refer my below javascript code , how to count rows if i click add
I have an add this button on the website that is rendering a border
I am trying to add a custom UIBarButtonItem to my navigationItem. This button will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.