How would I create an object in jQuery, and then proceed to make a couple of different instances of this object I.e

Create an object named box which holds a variable called color.

And then make a couple of instances of this object with different stored colours.

I want to explore object-oriented jQuery but do not know how to construct a class and then initialise an object – Ben_hawk Jul 6 '12 at 2:07 This is a job for javascript alone, jQuery is a framework built on javascript with its focus set on DOM manipulation, javascript is a language. It has become a common misconception that jQuery is a language itself. – Austin Jul 6 '12 at 2:08

Another way to make objects in Javascript using JQuery , getting data from the dom and pass it to the object Box and, for example, store them in an array of Boxes , could be:

var box = {}; // my object
var boxes =  []; // my array
$('div.test').each(function (index, value) {
    color = $('p', this).attr('color');
    box = {
        _color: color // being _color a property of `box`
    boxes.push(box);

Hope it helps!

function writeObject(color){
    $('body').append('<div style="color:'+color+';">Hello!</div>')

writeObject('blue') ➜ enter image description here

site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2019.10.18.35213