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.

2
  • 1
    use HTML/Javascript to remove link nodes from DOM. Commented Aug 21, 2014 at 5:28
  • 2
    /<link\b[^>]*?>/gi Commented Aug 21, 2014 at 5:28

4 Answers 4

2

remove all <link> tag?

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

Regular expression visualization

Debuggex Demo

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

6 Comments

Thanks, it's the most handy solution
how could I modify regex to remove all <script> tags as well?
@BubbaYakoza var reg= /<\/?script\b[^>]*?>/gi
@BubbaYakoza - It seems like you're getting very close to TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ now.
@Tim.Tang Thanks, it removes the script tags but does not remove the code in between. any help?
|
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

Comments

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.

Comments

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>')

};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.