2

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 Answers 2

1

Try this

$(".remove").live('click', function() {
  if ($(this).parent().hasClass('status_update')) // execute inner links code
  else // execute outer links code
});
Sign up to request clarification or add additional context in comments.

2 Comments

need to do this in two different calls
I think you will need to assign different class name for that. If you write $('.remove') it will always apply on all elements with class remove. If you don't want to change class name only to do it is have a check in function
1

You can test if the clicked anchor's parent's class name is .status and act accordingly, using either .unwrap or .remove:

$("a.remove").live('click', function() {
   if($(this).parent().hasClass("status")) { // or $(this).parent('.status').length
       $(this).unwrap("div.status");
   } else {
       $(this).remove();
   }
});

6 Comments

thanks karim for the answer, but i need to do this in two different calls, cant do it in one call, because one is global and other is sub section which changes to every different page.
@Basit - I'm a little lost. Do you mean .unwrap and .remove are what you need, only in the two event handlers in your question? Or is there some other problem?
@Basit - Why do you need two event handlers when a single one can take care of both link types using a conditional? Is there a special reason for that?
yes. i have two different javascript file. one is global and second is by the section. each section has there own file (media, feed...). so i cant put things in global file, need to keep them separate, which will keep things neat and easy to modify, remember and proper way.
Then for your second 'section' event handler, instead of $("status_update > .remove") use another selector like $("status_update > a").live("... to avoid confusion?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.