sephiith
sephiith

Reputation: 1197

How to select all classes inside a class with jQuery selector

How do I go about selecting all classes in a class using a jquery selector? You would think something like $(".content .*").click(); would work.

In addition, on click of any class in .content I want to store the class name of the clicked class in a variable.

Upvotes: 0

Views: 876

Answers (3)

Sushanth --
Sushanth --

Reputation: 55750

   var $allClassElements =  $('[class]', '.content')

should do

Then for further reference of these elements just use the cached variable

 $allClassElements.something

Upvotes: 0

zerkms
zerkms

Reputation: 254926

Here is a selector for all elements that have at least one class specified

$('.content [class]')

or here is just all elements

$('.content *')

or the better:

$('.content').on('click', '*', function() { //handler here });

Your second question doesn't make much sense and needs to be rephrased

Upvotes: 1

Chandu
Chandu

Reputation: 82903

If you are trying to select child elements of ".content" with any class, try this:

$(".content [class]").click

Upvotes: 0

Related Questions