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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:20:21+00:00 2026-05-25T23:20:21+00:00

So I am looking for a jQuery Plugin or a method using javascript in

  • 0

So I am looking for a jQuery Plugin or a method using javascript in general where I can obtain CSS properties from a string without using a lot of If else statements I have to write. The string comes from a user input like a Text area. Example:

var string = "#hello{border:1px #000 solid;background-color:#FFF;}";

So basically I want to be able to identify ID’s and Classes from a string and their properties. So in this case that there is an ID called Hello and that it has a 1px border and a background color of #FFF (white). The info will be then be added to an object asnd pushed into an array. Is there a plugin or a way I can do this? There will also be multiple in each string. I know this might seem a little confusing. 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-05-25T23:20:21+00:00Added an answer on May 25, 2026 at 11:20 pm

    It seems that you want to parse CSS style rules and extract the components. That isn’t too hard since the general syntax is a selector followed by a list of zero or more semi-colon separated sets of colon separated name:value pairs (i.e. selector { property : value; property : value; …}).

    A regular expression should do the trick, however it might get complex if you want the selector to be fully compliant with the current standard, CSS 2.1.

    If all you want is single id and class selectors, then life is much simpler. A start on such a function is:

      function parseCSSRule(s) {
        var a = s.indexOf('{');
        var b = s.indexOf('}');
        var selector = s.substring(0, a);
        var rules = s.substring(++a, b).split(';');
    
        // Do something with the selector and the rules
        alert(selector + '\n' + rules);
      }
    

    that will split the selector from the rules, then separate the rules into an array. You will need to deal with a bit of whitespace here and there, but otherwise if all you want to do is apply the (possibly empty set of) style rules to an element selected by the selector, that’s about it.

    You just need to split each rule on the colon “:” and apply the CSS text to the appropriate style property, changing hyphenated names to camelCase in the processs.

    Edit

    Oh, and if you want a really simple solution, just add the rule to the bottom of the last style sheet in the document. That way you don’t have to parse it at all, just drop it in and let the browser do the work.

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

Sidebar

Related Questions

I am looking for a jQuery plugin which can serve me the floating share
I'm looking at using the jQuery MetaData Plugin. Looks very interesting but... <li class=someclass
I'm looking for a plugin for jQuery that can validate as a key is
I am using the jquery-ui-dialog plugin I am looking for way to refresh the
I'm using jQuery's validation plugin and looking to validate many dynamically added text fields
I'm looking at jquery resize plugin and can't understand certain things about how it
I looking for jquery validator plugin. I have done lot of searches, some plugins
I'm using the jQuery template plugin to generate HTML from JSON data which the
I am looking for a method for the jquery validate plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ ),
I'm looking for a jquery plugin to simulate a vertical marquee. I need it

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.