[javascript] jQuery - adding elements into an array

I'm trying to add the ID's, which are the $hexcode values from the html span into an array. How do I do this with jQuery? Eventually, I'm going to need to grab these hexcode values and match them to a color index.

<?php
// display every color in the world

$r = 0;
$g = 0;
$b = 0;
$i = 0;
$step = 16;

for($b = 0; $b < 255; $b+=$step ) {
    for($g = 0; $g < 255; $g+=$step) {
        for($r = 0; $r < 255; $r+=$step) {
        $hexcolor = str_pad(dechex($r), 2, "0", STR_PAD_LEFT).str_pad(dechex($g), 2, "0", STR_PAD_LEFT).str_pad(dechex($b), 2, "0", STR_PAD_LEFT);
        echo '<span class="color_cell" id="'.$hexcolor.'" style="width: 5px; height: 5px; background-color:#'.$hexcolor.'; border: 1px dotted;">&nbsp;</span>'

        if($i%256 == 0) {
            echo "<br />";
        }
        $i++;
        }
    }

}
?> 
<script src="jquery-1.6.2.js"></script>
<script type="text/javascript">

var ids = [];

    $(document).ready(function($) {    
    $(".color_cell").bind('click', function() {
        alert('Test');
        //how do i add the ID (which is the $hexcolor into this array ids[]?
        ids.push($(this).attr('id'));       
    });
});

Thanks in advance!

This question is related to javascript jquery arrays

The answer is


var ids = [];

    $(document).ready(function($) {    
    $(".color_cell").bind('click', function() {
        alert('Test');

        ids.push(this.id);       
    });
});

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to jquery

How to make a variable accessible outside a function? Jquery assiging class to th in a table Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Getting all files in directory with ajax Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) bootstrap 4 file input doesn't show the file name Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource how to remove json object key and value.?

Examples related to arrays

PHP array value passes to next row Use NSInteger as array index How do I show a message in the foreach loop? Objects are not valid as a React child. If you meant to render a collection of children, use an array instead Iterating over arrays in Python 3 Best way to "push" into C# array Sort Array of object by object field in Angular 6 Checking for duplicate strings in JavaScript array what does numpy ndarray shape do? How to round a numpy array?