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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:49:26+00:00 2026-05-11T05:49:26+00:00

I am trying to dynamically set css with variables I retrieve from what a

  • 0

I am trying to dynamically set css with variables I retrieve from what a user types into a textfield.

This is the line of code:

$(get_elem_hierarchy()).css($(this).data('theCss').theProp, $(this).data('theCss').theVal); 

Everything works fine. Both the css property and the css value trace to the console correctly but for whatever reason it won’t set it. If I hardcode it works fine.

I have tried wrapping quotes around those as well and that doesn’t work either so that’s not the issue.

Am I missing something? I’ve looked all over and can’t find anything that even remotely comes close to discussing this issue so maybe I’m going about this the wrong way.

Any help would be greatly appreciated.

  • 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. 2026-05-11T05:49:26+00:00Added an answer on May 11, 2026 at 5:49 am

    Is there a specific reason you are using .data() ? According to jQuery site –

    jQuery.data(elem)

    Returns a unique ID for the element.

    Typically this function will only be used internally. You will likely not use the data() method in this way. It is called automatically when necessary when using the other data() functionality.

    I’ve set up an example of how you can type a css name and value into 2 input boxes and then apply them to a div, to verify that you can set CSS using variables.

    You can edit and play with the example here.

    As you can see, it uses the jQuery.val() command to get the text from within each textbox and assign each to a variable. Is this what you were intending to do?

    EDIT:

    Modified Example here

    that uses a textarea for input and allows you to specify multiple css attributes. This works because jQuery.css() can accept an object as a parameter, so we build an object with properties and their respective values based on the textarea value, and then pass that object into the jQuery.css() command. Just specify the attributes in the textarea as you would within CSS style tags i.e.

    background-color: red; height: 500px; width: 300px;  font-size: 20px; color: white;  

    and all will be applied to the <div> with id="mydiv"

    jQuery Code here –

    $(function() {      $('#mybutton').click(function(e) {      var cssObject = {},         cssName = null,         cssValue = null;          var cssAttributeString = $('#value').val();     var cssAttributeArray = cssAttributeString.split(";");      for (var i = 0 ; i < cssAttributeArray.length ; i++){         cssName = $.trim(cssAttributeArray[i].substring(0,cssAttributeArray[i].indexOf(":")));         cssValue = $.trim(cssAttributeArray[i].substring(cssAttributeArray[i].indexOf(":") + 1, cssAttributeArray[i].length));          cssObject[cssName] = cssValue;         }             $('#mydiv').css(cssObject);      });  }); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to dynamically generate a gif image of a specified size and color
Question I am trying to dynamically get the default for a type that is
I'm trying to dynamically define functions that call through to another function that takes
Trying to make a make generic select control that I can dynamically add elements
I am trying to send my dynamically created silverlight 2 page/image to a an
I trying to export an HTML table named Table that is dynamically binded to
I am trying to get a dynamically loaded LinkButton to fire a postback event,
I am trying to apply styles to HTML tags dynamically by reading in the
I am trying to compare the performance of boost::multi_array to native dynamically allocated arrays,
I am trying to dynamicaly compile code using CodeDom. I can load other assemblies,

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.