Click here to Skip to main content
15,896,040 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Solution

You can use Regex for this.
JavaScript
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.
JavaScript
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).
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900