i have two tag, which has same class but different trigger events, following is example:
我有两个标签,它具有相同的类但不同的触发事件,以下是示例:
<a class="remove">remove this</a>
<div class="status"><a class="remove">Remove this status div only</a></div>
in jquery i have it like
$(".remove").live('click', function()... (this gets trigger for both)
$(".status_update > .remove").live('click', function()... (i want this to trigger for status div remove link)
i need to do this in two different triggers, cant do it in same trigger call.
我需要在两个不同的触发器中执行此操作,无法在相同的触发器调用中执行此操作。
2 个解决方案
#1
1
Try this
$(".remove").live('click', function() {
if ($(this).parent().hasClass('status_update')) // execute inner links code
else // execute outer links code
});
#2
1
You can test if the clicked anchor's parent's class name is .status
and act accordingly, using either .unwrap
or .remove
:
您可以使用.unwrap或.remove测试单击的锚点的父类名称是否为.status并相应地执行操作:
$("a.remove").live('click', function() {
if($(this).parent().hasClass("status")) { // or $(this).parent('.status').length
$(this).unwrap("div.status");
} else {
$(this).remove();
}
});
#1
1
Try this
$(".remove").live('click', function() {
if ($(this).parent().hasClass('status_update')) // execute inner links code
else // execute outer links code
});
#2
1
You can test if the clicked anchor's parent's class name is .status
and act accordingly, using either .unwrap
or .remove
:
您可以使用.unwrap或.remove测试单击的锚点的父类名称是否为.status并相应地执行操作:
$("a.remove").live('click', function() {
if($(this).parent().hasClass("status")) { // or $(this).parent('.status').length
$(this).unwrap("div.status");
} else {
$(this).remove();
}
});