jQuery: remove elements after current one -


I have a question about removing all the elements after the existing one.

Here's the scenario:

I have a place tree that is lowered to my users to get a specific value. I have SELECT that loads top-level locations through AJAX. Data is more granular in terms of reducing the selection, so I add new selection based on the user's selection. When the user goes to the end of the available options for the data, then I stop adding SELECTs and catch the value of the last time that I am after that.

The way I codify it is to start with a selection that is hard-wired in the top-level location ID, after which there is an 'onen' event handler which goes to my database And catching children for that selection, then makes a new selection within the existing TD.

It continues till when no child is returned for the last choice, at that time, I can get the ID of this last place.

This works very well, as long as the user decides to select one or two "upstream".

Here is an example of what a user can be in the tree of the space given below (these are included in the code):

USA - & gt; Ohio - & gt; Kuyhoga - & gt; Cleveland - & gt; District 1

If 'District 1' was the last available item in this series of space, then I could get it using $ ('# location: last:'). Val () Wunderbar

What does not work good if the user decides, "hmm, no it is not kuhaga, i am later, but staw", and third changes the option. What I need to do is remove all the selections after the selection of 'Chuaaoga', because now I have to get more data for "stove". Selection after any pre-selection is no longer valid.

The selection that is being made passes through the changing event, so that I have the current element. I have tried $ (AMM). after this (). Remove (), but it does not work.

Any ideas on how I can remove all the selection after the present?

Thank you!

The doctor's structure looks something like this:

  & lt; Table boundary id = "compliant" & gt; & Lt; Tr & gt; & Lt; Th & gt; Location: & lt; / Th & gt; & Lt; Td> & Lt; Select ID = "loc0" onchange = "Update Location Change (this);" & Gt; & Lt; Options & gt; Choose .. & lt; / Options & gt; & Lt; Option value = "3" & gt; USA & lt; / Options & gt; & Lt; / Select & gt; & Lt; / TD & gt; & Lt; / TR & gt; [Snip]  
  function select update location (elem) {// load sub place for load PPID given. In this case, places under the United States. To add the option elem // After this, erase any selection, if the user has "backed up" their selection $ (elem). (). Remove (); // help needed here !! How to remove any selection after this one ?? $ Ajax ({url: "api.php", datatype: "jsan", data: {cms: "sublocs", "pid": elem.value}, async: wrong, success: work (data, text position) / Result if ($ (data) length) {$ ('#Lictable TD'). App ("click on onchange = 'Update location (select this);' & gt; & lt; option & gt; ; Select .. & lt; / option (gt; & lt; / select & gt; "); $ .each (data, function (key, val) {$ (select '#loclectable: last'). Append (' & Lt; option value = '' + + + + "+ & gt; 'Val +' & lt; / option & gt; ');});} else {// We have struck the end of this location branch. Val Warning is the right warning to check ("LocID:" + $ ('#': last '). Val ());}},}); Details are false;}    

  $ (elem) .nextAll (). Remove ();   

If you have to specify a selector, you can use the same method.

  $. (Elem) .nextAll ('select.some-class') to delete () .; < / Code>   

Comments