How to save jQuery object in a cookie?

What's the best way to get a string to act like an array/object in jQuery?

  • The plugin can be custom configured with multiple objects that define default values. The names of those objects will be developer defined - not predefined. Then based on "input" (e.g., form, parsing the CSS ids and classes, etc.) I want to use an "input" value to get the corresponding default object. (In case it's not clear, the input value would be a string of the same characters of a default object name.) Once I have the default values for the given input / object, I would proceed with using them in the plugin. Currently, when I try to .each the default parms when defining it with the "input" value, each parses that string, not the object the value of the string is asking for. Make sense? Pardon me if my jargon isn't accurate I'm somewhat new to this area of jQuery. In a nut shell, I'm looking for the jQuery equivalent of PHP $$ (double dollar sign).

  • Answer:

    I've created a demonstration of my best guess based on my understanding of what you've described: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-git.js"></script> <script type='text/javascript'>//<![CDATA[ $(function(){ var object = { "hi": "hello!", "bye": "good-bye!" }; $("#theinput").on("keyup", function() { var message = object[ $(this).val() ]; if ( message ) { $("#themessage").html( message ); } }); }); </script> </head> <body> Type: "hi" or "bye" <input type="text" id="theinput" value=""> <div id="themessage"></div> </body> </html> Live demo can be found here: http://jsfiddle.net/rwaldron/wZgCn/

Rick Waldron at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.