سؤال

i want to find an image in a table and then remove the image if it got a specific url.

 if (event.keyCode == 189) {
     $.each($('#id tr'), function(e, v) 
        {
            $(v).find('td:nth-of-type(4) img').filter(function () {
                return $(this).attr('src') === "src";
            }).remove();
        });
    }

i need to find that image with "src" and then remove the $(v)

هل كانت مفيدة؟

المحلول

  1. Get the image elements you need with .find().
  2. Use .filter() with a filter function to get only the images you need.
  3. The filter function will run for every image (this will always refer to the current image's DOM element). If you return true from the function, the image will be included in the result set - otherwise it is omitted.
  4. On the resulting set (that only includes the filtered images) call .remove().

Something like this:

$(v).find('td:nth-of-type(4) img').filter(function () {
    return $(this).attr('src') === THE_URL_YOU_WANT_TO_CHECK;
}).remove();

UPDATE:

After some clarification, it seems you want to remove the whole table row.

In this case you need to modify the code a bit:

$('#id tr').filter(function() {
    return $(this).find('td:nth-of-type(4) img').attr('src') === THE_URL_YOU_WANT_TO_CHECK;
}).remove();

And a little demo.

نصائح أخرى

Try .find() and .remove()

$(v).find('td:nth-of-type(4) img[src="URL"]').remove();

Attribute Equals Selector [name="value"]

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top