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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:51:31+00:00 2026-06-08T08:51:31+00:00

Here I created a jquery function that gets css-color and creates element with background

  • 0

Here I created a jquery function that gets css-color and creates element with background of css-color: Edit my jsFiddle

html

<div ID="wrapper">
    <div ID="addColor">
        <input type="text" ID="hex">
        <div ID="color">Your color</div>
        <button ID="add">Add color</button>
    <div CLASS="clear"></div> <!-- Clear float -->
    </div>

    <div ID="wrapGallery">
        <h1>My Color Gallery</h1>
        <ul ID="gallery"></ul>
    </div>
</div>

js/jquery

$(function() {
    //float left with some margin
    $('#addColor')
        .children().not('#add, .clear').css({
        'float':'left',
        'margin-right': '5px'
        });

    //Showing color on keyup
    $('#hex').keyup(function() {
       var hexCode = $(this).val();
       $('#color').css('background-color', hexCode);

        if ( hexCode !== '') {
            $('#color').text('');
        }else{
            $('#color').text('Your color');
        }

    });

    //Adding colors
    $gallery = $('#gallery');

    $('#add').click(function() {

        var storedHex = $('#hex').val();
        //check if empty
        if (storedHex == '') {
            alert('Enter something');        
        }
        else {
        //adding li
        $("<li>").css('background-color', storedHex)
                .hover(
                  function () {
                    $(this).text(storedHex);
                  }, 
                  function () {
                    $(this).text('');
                  })                    
                 .appendTo($gallery); 
        }
    });
});

The only thing I need to do is to save the created elements permanently in the file, so I can access whenever I want. I have no idea how to do that.

  • 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-08T08:51:32+00:00Added an answer on June 8, 2026 at 8:51 am

    Read up on JQuery Ajax function and also read about JSON objects.

    With AJAX and JQuery you can easily send a JSON object to your server like so:

    function saveElements(myJsonObj) {
      $.ajax({
        method: "POST",
        dataType: "json",
        url: "path/to/savemyobject.php",
        data: {json:myJsonObj}
      });
    }
    

    A JSON file may look something like this:

    { "myData":
      {
        "some_text":"this could be the CSS code",
        "name":"some name",
        "number":"some number"
      }
    }
    

    You could generate a JSON string representing a JSON object and send it to a PHP file with the Ajax function (as above).

    In PHP you would do this to obtain the object:

    <?php
    $json_string = $_POST["json"]; //the same variable key we sent it in
    $json_obj = json_decode($json_string, true);
    // get data
    $myDataCode = $json_obj["myData"]["some_text"];
    // do some processing
    ...
    ?>
    

    You could also convert an array in PHP to a JSON object using the PHP json_encode function.

    Read more:
    http://www.w3schools.com/json/default.asp
    http://php.net/manual/en/function.json-decode.php
    http://php.net/manual/en/function.json-encode.php
    http://api.jquery.com/jQuery.ajax/

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

Sidebar

Related Questions

I'm trying to create a popup for which I am using jQuery's CSS function.Here's
I have created a drop down with jQuery that can be seen here by
I have tied this jQuery Bar Graph plugin with a function that I created.
I have the following html code: (that gets loaded via ajax into a div)
I have created a jQuery plugin that is used to create html on a
I have created a dropdown menu with jquery: here Everything is ok but in
Has anyone here created a Flash site or application that is ADA (Section 508)
I am trying to emulate another form that the other developer here created. In
I know that many threads has been created here & on the internet about
I am trying to add an attirubute to objects that i created.Here i created

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.