Selecting standard html tables by a mutral css class
I have multiple tables with no id, a common class and a runat="server开发者_开发问答" tag. How do I dynamicly selected these tags and change a style attribute? EDIT: Jquery isn't an option, only server-side
You can loop through the elements by their common class name and then set their style attribute to something.
$('.<COMMONCLASSNAME>').each(function(index) {
$(this).attr('style', '<NEWSTYLE>');
});
if jQuery is an option for you: Class Selector if you want to do this change in the code-behind: Change Css-Class
You shouldn't need to add styles/class names to table elements. Properly composed CSS can be applied to an entire table with just a class name assigned to the
You can put all of your tables in one container like the Panel control...
<asp:Panel runat="server" ID="pnl">
<table >
</table>
...............
.......................
<table>
</table>
</asp:Panel>
Then iterate the panel control collection and check if the control type is HTMLTable, then add attributes to the class. e.g.
foreach (Control ctrl in pnl.Controls)
{
if (ctrl.GetType().Name == "HtmlTable")
{
((HtmlTable)ctrl).Attributes.Add("class", "test");
}
}
精彩评论