Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I have one html string and I Want to remove all style attribute from
of table except style attribute . So please help me out.
Posted
Updated 7-Mar-19 20:15pm
v2
Comments
Sergey Alexandrovich Kryukov 24-Mar-15 10:48am    
What would is supposed to mean: "...all style attribute except style attribute"? And may I ask why?
What have you tried so far?
—SA
Completely unclear.

If you want to remove inline css, there is no need to bother Regex, just use jQuery[^] and call .removeAttr() method[^] on the html element.
For example:
<p style="background-color: red">This is another paragraph.</p>

this will remove the style
$("p").removeAttr("style");

+++++[Round 2]+++++
To do it on code behind
aspx:
XML
<asp:Label ID="Label1" runat="server" Text="Label" style="background-color: red"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

aspx.cs:
C#
protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Style.Clear();
}
 
Share this answer
 
v3
Comments
nira.parmar 25-Mar-15 5:08am    
Hi Peter,

Thanks, but I want to do this at code behind(C#).
Peter Leow 25-Mar-15 7:07am    
addition to solution 1.
Please Have a look at this link,
regex style remove | C# Online Compiler | .NET Fiddle[^]
 
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