user1788736
user1788736

Reputation: 2845

How to remove image elements from string that has specific alt= value?

I have a string that contains HTML image elements that is stored in a var. I want to remove those image elements that has alt="today" and leave the rest of images untouched .

<img src="./images/ok.gif" alt="today" />

I have tried:

var replaced2 = content.replace(/\<img src="./images/ok.gif" alt="today" />\/g,'');

but had no luck. Can anyone help me out at all? Thanks

Upvotes: 0

Views: 324

Answers (3)

MaxOvrdrv
MaxOvrdrv

Reputation: 1916

what you need to look into is: JavaScript RegExp

Upvotes: -1

James Coyle
James Coyle

Reputation: 10398

You don't need a RegExp:

var replaced2 = content.replace('<img src="./images/ok.gif" alt="today" />','');

jsFiddle

Upvotes: 2

m1.
m1.

Reputation: 1325

Try this as your regular expression:

/<img src=".\/images\/ok.gif" alt="today" \/>/g

Gotta make sure to escape any forward slashes because they denote a regexp

/<regexp syntax>/

Upvotes: 1

Related Questions