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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:41:13+00:00 2026-05-29T08:41:13+00:00

How do you add boolean attributes using JavaScript? For example, how can you change:

  • 0

How do you add boolean attributes using JavaScript? For example, how can you change:

<p> to <p contenteditable>

<p> to <p data-example>

  • 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-05-29T08:41:13+00:00Added an answer on May 29, 2026 at 8:41 am

    In general, you can use element.setAttribute('attributeName', 'value') or element.propertyName = value to toggle an element’s attributes or properties.

    Boolean attributes

    For boolean attributes, set the attribute with the same-named value:

    element.setAttribute('disabled', 'disabled');
    

    Removing a boolean attribute works the same way as other attributes:

    element.removeAttribute('disabled');
    

    However, neither of your two examples are boolean attributes!

    contenteditable

    contenteditable is not a boolean attribute, it’s an enumerated attribute. Its possible values are the empty string, "true", and "false".

    While setAttribute seems overkill in this case, you could use it:

    element.setAttribute('contenteditable', 'true');
    // to undo:
    element.removeAttribute('contenteditable');
    

    The property name for the contenteditable attribute is contentEditable (note the capital E), and it recognizes the values 'true', 'false', and 'inherit' — so you could just use:

    element.contentEditable = 'true';
    // to undo:
    element.contentEditable = 'false';
    

    Note that 'true' and 'false' are strings here, not booleans.

    data-example

    For the data-example attribute, you could use:

    element.setAttribute('data-example', 'some value'); // the value should be a string
    // to undo:
    element.removeAttribute('data-example');
    

    Or, in browsers who support dataset (see the ones highlighted in light green on http://caniuse.com/dataset), you could use:

    element.dataset.example = 'some value';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to this when a button is clicked. For example: imgBtnDelete.Attributes.Add(onclick, return
I want to implement a feature where user can add new attributes to his
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Whats wrong with my query? ALTER TABLE test_posts ADD sticky boolean NOT NULL default
We add Struts errors and messages using ActionSupport.addActionError(...) and addActionMessage(...) and then output the
I add many check boxes to the excel sheet programaticaly using the following code:
I am using Core Data programmatically (i.e. not using .xcdatamodel data model files) in
I can't seem to find an example that is complete in all the components.
Following the guide here, I added a boolean attribute to my database using a
I am using spring 3 and I tried to add exception mapping this way:

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.