如何选择多个类的跨度并放置在锚点内? [英] How to select a span with multiple classes and placed inside an anchor?
问题描述
我需要将点击事件绑定到跨度(放置在具有多个类的achor内)。例如:
更新:添加了如下所示的html
< div class =c0 c>
< a class =c1 c2>
< span class =c3 c4>< / span> Anchor_Text
< / a>
< / div>
现在我要绑定一个点击事件,如下所示:
$('span.c3.c4')。click(function(e){alert(clicked!);});
上面的jQuery代码不起作用。但是,如果我使用锚点上的类来绑定点击事件,它就可以工作。请参阅以下内容:
$(。c1')。click(function(e){alert(clicked!); });
$ b $(.c2')。click(function(e){alert(clicked!);});
任何帮助将不胜感激!
更新:请在Q中更新html示例。
应该像这样选择多个类:
$ b $
$('span.c3.c4')。parents('a')。click(function(e){alert(clicked! );});
在这里查看工作演示> http://jsfiddle.net/JeG3A/
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.
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/
这篇关于如何选择多个类的跨度并放置在锚点内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!