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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:31:19+00:00 2026-06-15T02:31:19+00:00

Are you allowed to set the ID of an HTML element dynamically – i.e.

  • 0

Are you allowed to set the ID of an HTML element dynamically – i.e. as a simple example, can i do:

<a href="#" id="onOrOff()">Jazz</a>

And:

function onOrOff()
{
 document.write("someIDSetInMyCSSFile");    
}

I’ve tried it and it doesnt work so just want to check whether or not I’m missing some other point.

Thanks.

  • 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-15T02:31:20+00:00Added an answer on June 15, 2026 at 2:31 am

    Update: Created a jsFiddle for this solution: http://jsfiddle.net/SdvA2/3/ Feel free to experiment!

    Assuming that your CSS refers to #coolLink (and/or #uncoolLink)you could try something like this:

    <a href="#" id="uncoolLink" onclick="makeCool()">Jazz</a>
    

    To turn on coolLink id formatting dynamically you can try using these functions:

    <script>
    function makeCool() {
      var element = document.getElementById("uncoolLink");
      element.id ="coolLink";
    }
    </script>
    

    See more here: https://developer.mozilla.org/en-US/docs/DOM/document.getElementById

    However, I would strongly recommend keeping the id constant and simply changing the class (and adjusting your css accordingly).

    Going one step further, I would recommend using jQuery as this will open up a world of possibility, change the way you approach things, make life so much easier and protect you from browser incompatibilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I set variables inside if-construct? In general, where is it allowed to set
I have the following lines in my ~/.emacs.d/init.el (custom-set-variables '(flymake-allowed-file-name-masks (quote ( (\\.cc\\' flymake-simple-make-init)
My html purifier settings now allow only these tags $configuration->set('HTML.Allowed', 'p,ul,ol,li'); I want to
Is the ID attribute on an HTML element allowed to be empty? <div id=></div>
How to enable textarea tags in HTMLPurifier ? I tried with: $config->set('HTML.Allowed', 'textarea'); But
my channel url is set as channelUrl : '//www.example.com/xyx/channel.html' content of channel.html is <script
If I set up a central Mercurial Repository where certain people are allowed to
I have a promotional Facebook page set up which anyone is allowed to comment
I have this little NetStream movie (which I'm not allowed to show, sorry) set
I use this configuration: $config = HTMLPurifier_Config::createDefault(); $config->set('Core.Encoding', 'UTF-8'); $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $config->set('HTML.SafeObject',

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.