-2

Hi at the minute I am selecting classes like so...

$('.colorPick').each(function() {
});

Is there a way to select a class name with no event attached, ie in this case

.each

I have tried,

$('.colorPick').(function() {
   });

But it doesn't work?

amurra
  • 15,221
  • 4
  • 70
  • 87
cgweb87
  • 441
  • 1
  • 5
  • 14
  • 2
    `.each` is a function, not an event. If you just want an array of elements, you can do `var list = $('.colorPick');` – Sam Dufel Nov 08 '11 at 01:26
  • 1
    `each` isn't an event though. So what is your end goal? – Joe Nov 08 '11 at 01:26
  • 1
    I don't understand; what are you trying to do? – Dave Newton Nov 08 '11 at 01:26
  • Since you have many elements with the same class i do not think it possible to get the unique element with just that class you can get the class of the element but you might use somethink like id `var class = $(#id).attr('class');` – COLD TOLD Nov 08 '11 at 01:32

3 Answers3

1

Do you mean like this?

var $colorPics = $('.colorPick');

$colorPics will be a jQuery object (which is a container) and will hold the elements.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • Ok will try this, it is because with html5 canvas the only way to select it is with a id, not class! – cgweb87 Nov 08 '11 at 01:29
1

Maybe this can be used to filter out elements with events already attached: How to check if any JavaScript event listeners/handlers attached to an element/document?

Community
  • 1
  • 1
Syska
  • 1,150
  • 7
  • 26
0

jQuery objects are just objects that contain lists of elements. You can use them for many things beyond attaching event handlers. For example, to iterate through each object that matches a given selector, you can do this:

$(document).ready(function() {
    $('.colorPick').each(function() {
       // do anything you want here
    });
});

Note that I enclosed this in a document.ready block so that the code runs after the page loads. You can see a demo here: http://jsfiddle.net/jfriend00/87u2n/.

jfriend00
  • 683,504
  • 96
  • 985
  • 979