Click here to Skip to main content
14,421,274 members
Rate this:
Please Sign up or sign in to vote.
See more:
This is What I have when I do quick watch, In the innerHtml
<img style="width: 100%; height: 320px;" src="img/banner03.jpg">
  <div class="bjqs-caption">
      Automatically generated caption3
  </div>


But What I want in the innerHTML as :
<div class="bjqs-caption">
        Automatically generated caption3
   </div>


How will as remove img tag from the innerHTML
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Solution

You can use Regex for this.
var imgRegex = new RegExp("<img[^>]*?>", "g");

This Regex matches the image tags.
After matching, it is just a matter of replacing matched string with blank.
str.replace(str.match(imgRegex), "");


Demo

[Demo] Regex to Match Image tags[^]
You can see that alert is showing the string without the image tag (only the div).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100