0

I have a string, say:

<div class="thumb"><img src="/static/img/uploads/img3.png" class="bordered"></div> <div class="thumb"><img src="/static/img/uploads/img4.png" class="bordered"></div> <div class="thumb"><img src="/static/img/uploads/img10.png" class="bordered"></div> <div class="thumb"><img src="/static/img/uploads/img99.png" class="bordered"></div> 

How do I go about removing <img> with an SRC that matches a variable, say $imgURL

1 Answer 1

2

Since you want to process a html string, i would use

var string = '<div class="thumb"><img src="/static/img/uploads/img3.png" class="bordered"></div><div class="thumb"><img src="/static/img/uploads/img4.png" class="bordered"></div><div class="thumb"><img src="/static/img/uploads/img10.png" class="bordered"></div><div class="thumb"><img src="/static/img/uploads/img99.png" class="bordered"></div>'; var imgurl = ''; var $tmp = $('<div />', { html: string }); $tmp.find('div.thumb img[src="' + imgurl + '"]').parent().remove(); //not if you want the updated string then var newstring = $tmp.html(); 

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.