views:

154

answers:

4

I am doing an AJAX call that returns some HTML and jQuery:

<div id='selected'>Here is my Selection Text 
<a id='trashSelected' href=\"javascript:void(0);\">Remove</a>
</div>
<script>
        $('#trashSelected').live('click',function delete() 
        {

          // remove the container
          $('#selected').remove();

          substractSelectionCount();
          return false;
        });
</script>

The jQuery removes the container that was added if the user clicks on the link "Remove". It does the job removing the container, but the call to substractSelectionCount(); never occurs. should I be doing the call to this function in a different way?
This is a function that was already in the document. Tested in FF, IE 8 and Safari

A: 

I might be missing something, but have you tried it this way?

$('#trash{$roleId}').live('click',function delete() 
{

  // remove the container
  substractSelectionCount();
  $('#selected').remove();
  return false;

});
code_burgar
I don't know why, but when I do that the $('#selected').remove();doesn't work. and substractSelectionCount is still not being called
Onema
what's inside the substractSelectionCount() function?
code_burgar
function substractSelectionCount(){ currentSelectionCount--; }
Onema
A: 

There seems to be a syntax error in your function callback remove the word delete

    $('#trash{$roleId}').live('click',function(e) {
      e.preventDefault();
      alert('trash clicked');
      // ...
      return false;
    });
bendewey
removing the delete doesn't help either
Onema
A: 
Onema
A: 

Is your currentSelectionCount a global variable? Maybe the function is being called and it's not working because of this?

And did you try adding an alert into the function to make sure it's not being called?

function substractSelectionCount(){
 alert("I'm working!");
 currentSelectionCount--;
}


I put together a test file in this pastebin and it appeared to be working perfectly with IDs... but since I added three divs to test it I had to replace the IDs with classes. So, I'm not sure where your code is having problems - maybe your substractSelectionCount function is outside of the document.ready function?

fudgey
this variable is not declared as a global, but the problem is that the code returned when executed the browser would give an error message like "undefined function substractSelectionCount"
Onema
I added a demo of the script working in the post above. Maybe it will help you troubleshoot your problem?
fudgey