Tejas Shyani
Tejas Shyani

Reputation: 23

Remove HTML by div id inside C#

See below code, I want to remove particular content in between from full html source code.

do anyone has suggestion?

var hmtl = '<DIV><div>This is test things.</div><div id='test'><div class='ourteam_link'> < ul class='ourteam_menu_left'> <li class='active'><a href = '#' > All Candidates</a></li> <li><a href = '#' > Favorites </ a ></ li > < li >< a href='#'>Hidden</a></li>  </ul><span>Sort by: <a href = '#' > Rank </ a ></ span > </ div ></div><div>Footer remain</div></DIV>';

int a = hmtl.IndexOf("<div id='test'>");
int b = hmtl.LastIndexOf("<div id='test'>"); 
hmtl = hmtl.Remove(a, (b - a));

Upvotes: 0

Views: 452

Answers (1)

Baber Ali Siddique
Baber Ali Siddique

Reputation: 411

You can use javascript to do that.

<div>
  <div>This is test things.</div>
  <div id='test'>
    <div class='ourteam_link'>
      <ul class='ourteam_menu_left'>
        <li class='active'>
          <a href='#'>All Candidates</a>
        </li>
        <li>
          <a href='#'>Favorites </a>
        </li>
        <li>
          <a href='#'>Hidden</a>
        </li>
      </ul>
      <span>Sort by: <a href='#'>Rank </a>
      </span>
    </div>
  </div>
  <div>Footer remain</div>
</div>


<script type="text/javascript">
//Calling function
myFunction();

function myFunction() {
  var x = document.getElementById("test");
  x.innerHTML = '<div>New</div>';
}
</script>

Upvotes: 1

Related Questions