2

I have a code use jQuery, and ajax

$.post(
  'http://example.com', {
    abc: $abc
  },
  function(data) {

    $.post(
      'http://example.com/123', {
        cde: cde
      },
      function(data12) {

        $.each($.parseJSON(data12), function(idx, obj) {

          var $response = $(data);
          $xyz = $response.filter('.abc[value="' + obj + '"]');
          $xyz.remove();
          console.log($xyz.html());
        });
      }
    );
  }
);

Expamle:

data =

<div class="abc" value="1"><span>abc</span></div>
<div class="abc" value="2"><span>def</span></div>
<div class="abc" value="3"><span>ghj</span></div>
<div class="abc" value="4"><span>xyz</span></div>

date12 = ["1","2"]

console = <span>abc</span> <span>def</span> <span>ghj</span> <span>xyz</span>

but the one I want is console = <span>ghj</span> <span>xyz</span>

The things I want is use jquery find and remmove something in ajax resposive and then save it.

Can anyone help me how to do please.

Seth
  • 10,198
  • 10
  • 45
  • 68
Steve Phuc
  • 1,168
  • 2
  • 11
  • 12

1 Answers1

1

I guess you want this: JQuery, remove element from string

Here's the actual code duplicated from that answer:

var s = '<h1>heading</h1><p>para</p>';

var $s = $(s).not('h1');

$('body').append($s);​

...or this one, also from that thread:

var s = '<div><h1>heading</h1><p>para</p></div>';

var $s = $(s).find('h1').remove().end();

$('body').append($s);​

EDITED: If you have more than 1 top-level element within the string, you'll have to wrap it inside another div beause $() function wants string with a single top-level element:

...
var $s = $('<div>' + s + '</div>').find(...).remove()
...
Community
  • 1
  • 1
Andrew Dunai
  • 3,061
  • 19
  • 27
  • I use that one but it not word can you help me what is wrong http://jsfiddle.net/q9crX/459/ – Steve Phuc Nov 29 '14 at 03:27
  • @nhphuc wrap the entire string into a single
    ...
    and it should do the trick! The thing here is that $() wants string with **element**, but you provide the _list_ of elements. So just put it in another div, i.e. `var $s = $('
    ' + s + '
    ')...`. Here's an example of edited fiddle: http://jsfiddle.net/andunai/q9crX/461/
    – Andrew Dunai Nov 29 '14 at 03:33