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

  • Home
  • SEARCH
  • 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 7019041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:07:51+00:00 2026-05-27T23:07:51+00:00

Is it possible to give a HTML element a new custom attribute? You know

  • 0

Is it possible to give a HTML element a new custom attribute?

You know how a “img” html element has the attribute .src:

imgEle.src = "";

Can I dynamically give a HTML element my own custom attribute .animationInterval? Is it as simple as this?…

imgEle.animationInterval = setInterval(...,10);

Maybe I do it the xml kindof way?…

imgEle.setAttribute("animationInterval", setInterval(...));

Whats the best way to do this?

  • 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-27T23:07:52+00:00Added an answer on May 27, 2026 at 11:07 pm

    The best way is to use html5 data- attributes:

    $(imgEle).attr("data-animateinterval", "12");
    

    Which can then be read back with

    $(imgEle).data("animateinterval");
    

    Which of course can also be added directly to your markup

    <img src="foo.png" data-animateinterval="12" />
    

    Also, if you’re not concerned about whether a new attribute is added to the actual html element, but just want some arbitrary data associated with it, you can simply do this:

    $(imgEle).data("animateinterval", "12");
    

    And retrieve it like this:

    var animateInterval = $(imgEle).data("animateinterval");
    

    Note however that as Esailija explains, this may or may not actually add a new attribute to your element; it may just store this data internally. If that’s not a concern for you, and I can’t think of any reasons why it should be, then you may prefer this more succinct syntax.

    To be clear, no matter which way you store it, $(imgEle).data("animateinterval"); will still work just fine.

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

Sidebar

Related Questions

can i perform select single node from IXMLDOMElement ,if its possible give me one
Possible duplicate: How can i give app store link in my apps before approving
is it possible to have a visible html element but one which lacks presence
I know that $(#divId).html() will give me innerHtml. I also need its styles (which
We can give some information in HTML form. Then different peoples provides different HTML
Is it possible to give a different color to each row that has distinct
Is it possible to use sessions on html.erb file? If so please can someone
Possible Duplicate: Convert HTML + CSS to PDF with PHP? Please give code for
Is it possible to give individual cells in a data grid view row different
I was wondering if it is possible to give people something when they join

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.