0

Here is code:

   <div class="rightColoumn" id="divreports">
       <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon">
       <link href="../ClientScript/General.css" rel="stylesheet" type="text/css">
    </div>

I wish I could remove lines completely.

javascript String object strObject contains this html.

Bubba Yakoza
  • 749
  • 2
  • 9
  • 17

4 Answers4

2

remove all <link> tag?

   var reg= /<link\b[^>]*?>/gi

Regular expression visualization

Debuggex Demo

Tim.Tang
  • 3,158
  • 1
  • 15
  • 18
2

How about just parsing it as what it is, HTML

var strObject = '<div class="rightColoumn" id="divreports"><link href="/favicon.ico" rel="shortcut icon" type="image/x-icon"><link href="../ClientScript/General.css" rel="stylesheet" type="text/css"></div>';

var parser = new DOMParser();
var doc    = parser.parseFromString(strObject, "text/html");
var parent = doc.getElementById('divreports');
var links  = parent.getElementsByTagName('link');

for (var i=links.length; i--;) parent.removeChild(links[i]);

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

here's another way to remove < link tag lines:

strObject.replace(/^.*<link.*$/mg, "");

It will work if your string has line break '\n' at the end of each line.

Abdul Jabbar
  • 2,573
  • 5
  • 23
  • 43
0

Here try this way to remove html tag

    //link
      var reg= /<link\b[^>]*?>/gi



    return this

        .replace(reg, '$1<link href="http://$2">$2>')

};
channasmcs
  • 1,104
  • 12
  • 27