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 8559171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:58:44+00:00 2026-06-11T15:58:44+00:00

With the following setup : <div id=foo/>​ JavaScript (jQuery 1.8.0): $(‘#foo’).removeProp(‘id’).prop(‘id’, ‘bar’); alert($(‘#bar’).length); alert($(‘#foo’).length);

  • 0

With the following setup:

<div id="foo"/>​

JavaScript (jQuery 1.8.0):

$('#foo').removeProp('id').prop('id', 'bar');

alert($('#bar').length);
alert($('#foo').length);
alert($('#undefined').length);​

Note that the elements ID has not been updated to bar as I expected it to be (only the final alert yields 1) (Chrome 21)

This seems to be related to my use of removeProp('id'); which, whilst redundant in this example (when I can just set the id to bar directly), is required in my final code.

Now I’m curious as to what the correct way is to remove an ID in JavaScript; should I have used removeAttr()? Is this a bug in jQuery? Is it legal to remove an ID once setting it?

  • 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-11T15:58:46+00:00Added an answer on June 11, 2026 at 3:58 pm

    There are two things to note, here, the first is that the id is an attribute, not a property, so attr()/removeAttr() should be used instead.

    The second is the the API for removeProp() explicitly note that you should not:

    …use this method to remove native properties such as checked, disabled, or selected. This will remove the property completely and, once removed, cannot be added again to element. Use .prop() to set these properties to false instead.

    Also, rather than unsetting, and then setting, why not simply change it with attr():

    $(elem).attr('id', 'newValue');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following setup: <div>Element with CSS3 animated height change</div> <div><a href=#>Link</a></div> I
Ive got the following html setup: <div id=div1> <div id=content1>blaat</div> <div id=content1>blaat2</div> </div> it
I'm having the following setup of jQuery UI tabs: $(function() { $('#tabs').tabs({ ajaxOptions: {
I have HTML similar to the following in my page <div id=someDiv> <img src=foo.gif
I have the following setup on 2 div tags: <div id='div1' style='position: absolute; z-index:
I have the following title div setup, but when only the leftmost div has
I have a website with the following setup: <div id=container> <div id=header></div> <div id=content></div>
I have the following ul setup: <div id=sidebar> <ul id=themenu class=sf-menu sf-vertical> <li> <a
The following configuration works - it loads the Edit view into a div: jQuery:
Within a web form I have the following jQuery setup to call a method

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.