including the dynamically fluctuating data into the ng-binding

Currently, a json is being generated using ng model and then placed in a binding box at the bottom of the page with ng-binding. The dynamic colourpicker is altering two elements - the textbox and box. You can see an example here: http://codepen.io/voronianski/pen/zpahm

I am looking to obtain either the text hex code (preferred) or the RGB code, both are feasible options.

The code structure matches that of the codepen example provided.

  <script type="text/javascript">
  var hexText="";
  var colorList = [ '000000', '993300', '333300', '003300', '003366', '000066', '333399', '333333',
  '660000', 'FF6633', '666633', '336633', '336666', '0066FF', '666699', '666666', 'CC3333', 'FF9933',
  '99CC33', '669966', '66CCCC', '3366FF', '663366', '999999', 'CC66FF', 'FFCC33', 'FFFF66', '99FF66'];
var codeHex = $(this).data('hex');
hexText = codeHex;
var picker = $('#color-picker');

for (var i = 0; i < colorList.length; i++ ) {
picker.append('<li class="color-item" data-hex="' + '#' + colorList[i] + '" style="background-color:' + '#' + colorList[i] + ';"></li>');
}

$('body').click(function () {
picker.fadeOut(1);
});

$('.call-picker').click(function(event) {
event.stopPropagation();
picker.fadeIn(1);
picker.children('li').hover(function() {
  var codeHex = $(this).data('hex');

  $('.color-holder').css('background-color', codeHex);
  $('#pickcolor').val(codeHex);
});
});
  </script>

Html

<div class="color-wrapper">
  <p>Choose color for Header</p>
   <!-- ng-model="eventData.header" This is to post the information in the color picker box into the json at the bottom to make it useable by the server. -->
  <input type="text" name="custom_color" ng-model="eventData.header" placeholder="#FFFFFF" id="pickcolor" class="call-picker">
  <div class="color-holder call-picker"></div>
  <div class="color-picker" id="color-picker" style="display: none"></div>
</div>

Answer №2

Here is the updated text regarding the Hex code:

var codeHex = $(this).data('hex');

The value of the Hex code is then assigned to a textbox using the following code: $('#pickcolor').val(codeHex);

To access this value outside of the function, you can declare a variable like so:

var hexText="";
var colorList....
....
var codeHex = $(this).data('hex');
hexText = codeHex;

If you only require the hex code without the sharp symbol, look into string manipulation functions in JavaScript.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The combination of Inline CSS and Bootstrap classes does not seem to be functioning properly

I'm new to web design and currently working on a website project. My concept involves hiding the #login-box when the user clicks on the login button, and displaying another element (.dashboard) in its place. Initially, I set the .dashboard class to ha ...

Only the initial TinyMCE editor that was added dynamically is visible, the rest are not showing

I am currently developing a javascript application that will showcase a real-time discussion thread. The app will regularly communicate with the server to fetch new data and display it on the page. To enable users to post comments and replies, we have deci ...

The method is triggered multiple times

Why does calling a method in my controller result in the object.name being logged multiple times? (function(){ var app = angular.module('portfolio', ['ngRoute' ]); app.controller('ReferenceController', function(){ ...

Utilizing Redux Reselect for Comment Filtering

Currently, I am attempting to filter and showcase comments that have a matching 'postID' with the current post id. Utilizing Redux/Reselect, the functionality works well but occasionally an error pops up indicating that post._id is undefined/null ...

Convert the values in the array from strings to numbers

My array contains the following values: var items = [Thursday,100,100,100,100,100,100] I am retrieving these values from the URL query string which is why they are all in string format. I am looking for a way to make all columns except the first one as ...

Troubleshooting: Issue with dynamically updating innerHTML of element using AJAX in response to selection input change event

I'm facing a challenge in retrieving the value of a product from a database based on user selection in a <select> element and displaying this value using AJAX in another element. When I directly access precio.php?q=PRODUCTO%201, it returns the d ...

Searching for MongoDB key names for querying and filtering purposes instead of focusing on values

My goal is to search for all keys within a collection that partially match a specific string. So far, I've only been able to check if a key exists, but it has to be an exact match. Here's the code I've used: db.collection.find({ "fkClientI ...

Using a string variable in a dynamic import with React is not supported

I am utilizing a component in React that allows me to import images dynamically. Here is the code for the component: import React from "react"; import PropTypes from "prop-types"; // Lazily load an image class LazyImageLoader extends React.Component { ...

Steps on closing an Angular strap modal after submitting a form:

<div class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog "> <div class="modal-content"> <div ng-controller="externalController"> <form role="form" name="detailForm" ...

There was an issue with the AJAX call: Error - NetworkError: DOM Exception 19

Encountered an issue when attempting to perform a cross domain ajax request. Error message: NetworkError: DOM Exception 19 Seeking assistance with this problem. Feeling very stuck and frustrated :( ...

jquery single click doesn't trigger on mouse press or hover

http://jsfiddle.net/vd6vG/ When you press the mouse button over the td's, they change color to red. However, when you click on them, nothing happens. This leads me to believe that a click event does not trigger a mousedown event. How can I make it w ...

The hover effect fails to function properly after altering the background color. The default color setting is transparent

<button class="button-main slide">Slide Left</button> .button-main{ color: black; outline: none; background: transparent; border: none; letter-spacing: 0.0625em; padding: 8px 10px; text-transform: uppercase; font: b ...

Conceal all video containers once a single one is chosen

Having recently delved into Javascript, I am encountering some difficulties in crafting the correct code for a specific function. The scenario involves multiple div elements, each containing 2 child div elements that switch places upon being clicked. Con ...

Is it true that Firefox fails to display javascript errors on AJAX 'threads'?

Currently, I have a function called test_fn that is being called in two ways: (a) Through an onclick event of a button; or (b) from the success callback within a jQuery AJAX request, as shown here: $.ajax({ type: 'POST', ... succes ...

Manipulating an SVG graphic's attributes by linking them to an external geometry in Three.js

Delving into the world of Three.js, I've embarked on a project to design a 3D kit creator for my college assignment. Through my study, I've grasped the basics of setting up scenes, scene objects, geometries, materials, and textures. I've r ...

"An error occurred while trying to retrieve memory usage information in Node.js: EN

Is there a way to successfully run the following command in test.js? console.log(process.memoryUsage()) When running node test.js on my localhost, everything runs smoothly. However, when attempting to do the same on my server, I encounter this error: ...

Having trouble incorporating symbols with functionalities using HTML, CSS, and JS

I have implemented a table with three columns: "Action", "Question Subquestion/Text", and "Sort order". Additionally, I have incorporated a feature that allows for drag and drop functionality on the rows. Below is my code snippet: <!DOCTYPE html> &l ...

PHP strtotime is adding an extra hour to my time

Within my database table, I have a datetime stored as '2014-08-05 15:12:00'. After using strtotime() to convert this date to milliseconds, on the client side I create a new Date object as follows: var date = new Date(date_in_milliseconds) Ho ...

Issue with implementing slide animations in Reactjs when target dimensions are not predetermined

Im implementing animations in my react app to enhance the user experience. I am trying to achieve a slide-in effect for a div to appear and a slide-out effect for it to disappear. My current tech stack includes bootstrap 5.1.0 and react-bootstrap 1.6.1. ...

CSS code for creating thumbnail images that enlarge when hovered over

I currently have a series of thumbnails in a row (within container elements) set to float left. These thumbnails are resized to fit neatly within the row. <style type="text/css"> .thumbnails{ float:left; position:relative; } ...