0

I'm in a situation where I need to bind a click event to a span (placed inside an achor having multiple classes) based on the classes applied to it.

For eg:

UPDATE: Added the html eg below

<div class="c0 c">
    <a class="c1 c2">
    <span class="c3 c4"></span>Anchor_Text
    </a>
</div>

Now I'm binding a click event as below:

$('span.c3.c4').click(function (e) { alert("clicked!"); });

The above jQuery code doesnt work. However if I use the classes on anchor to bind the click event, it works. Please see below:

$(.c1').click(function (e) { alert("clicked!"); });

$(.c2').click(function (e) { alert("clicked!"); });

Any help will be appreciated!

UPDATED: Please find the html example updated within the Q now.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Evolving Techie
  • 159
  • 1
  • 3
  • 13

1 Answers1

0

Multiple classes should be selected like this:

$('span.c3.c4').parents('a').click(function (e) { alert("clicked!"); });

See a working demo here > http://jsfiddle.net/JeG3A/

BenM
  • 52,573
  • 26
  • 113
  • 168