hello,
how would I target the third table (with CSS2) on a page if it has no id or class name to it? The table is generated by asp.net so I cannot name/id it.
For example:
/* want to apply CSS to this table */
let me know if you need additional info to help with this.
thanks
**modified to show
**modified to show code**
hello,
how would I target the third table (with CSS2) on a page if it has no id or class name to it? The table is generated by asp.net so I cannot name/id it.
For example:
<body> <table> </table> <table> </table> <table> /* want to apply CSS to this table */ </table> <table> </table> </body>
let me know if you need additional info to help with this.
thanks
You can use jQuery or modify
You can use jQuery or modify the ASP... no way to do it with CSS that I am aware of
fxCSS wrote: ... The table is
... The table is generated by asp.net so I cannot name/id it. ...
Why not?
:nth-of-type(3)
With CSS3 you can use
table:nth-of-type(3){background:red;}
It's supported by most modern browsers excluding IE http://csscreator.com/content/nth-type
Tony wrote: With CSS3 you can
With CSS3 you can use
Ya, OP mentioned CSS2, so I am assuming it has to work with IE, which is why I assume there was no other option besides modify the ASP or do it with JS.
Yes, sorry I only see what I
Yes, sorry I only see what I want, sometimes.
so in JavaScript you could do:
var tables = document.getElementsByTagName('table'); tables[2].style.backgroundColor = 'red';
or something similar.
It's much better to use a
It's much better to use a class then to write styles in your js,
var tables = document.getElementsByTagName('table'); tables[2].class = "thirdTable"
I think you can do this , not used to coding pure js, use jquery now
jQuery would be
$(document).ready(function(){ $("table:first").next().next().addClass("thirdTable"); });
Hope this helps
jQuery could also be done as
jQuery could also be done as
$(function(){ $("table").eq(2).addClass("thirdTable"); });
eq starts counting at 0, so number 2 is technically the third one.
className
tables[2].class = "thirdTable"
Should be
tables[2].className = "thirdTable";
Verschwindende wrote: fxCSS
... The table is generated by asp.net so I cannot name/id it. ...
Why not?
I still want to know how the table is generated and why it can't be targeted by adding a class or using the generated ID. Seems much simpler than futzing around with all the ancillaries.
It all depends how many
It all depends how many tables one of the ASP controls is building, if it's more than one then you can add a class in the Layout Template for the control and you will have to access it using jQuery or pure JavaScript using the solutions detailed above.
If the ASP control is only creating one table, then give it a class and you can access it easily using CSS. Giving a control a class is a workaround for controlling the presentation of an ASP or .NET control using CSS because these technologies dynamically create IDs for each control for server side code to work with them. Hope this helps
OP, show the code.
OP, show the code.
Hello??? Hello???
Hello??? Hello???
jon19870 wrote: It all
It all depends how many tables one of the ASP controls is building, if it's more than one then you can add a class in the Layout Template for the control and you will have to access it using jQuery or pure JavaScript using the solutions detailed above.
If the ASP control is only creating one table, then give it a class and you can access it easily using CSS. Giving a control a class is a workaround for controlling the presentation of an ASP or .NET control using CSS because these technologies dynamically create IDs for each control for server side code to work with them. Hope this helps
thanks everyone for their input. I really appreciate it.
hey Jon..
I don't really have access to the framework code...only the CSS files. There are many tables on each page which .NET is creating...
I am guessing I will have to use javascript in this case...?
I thought I could do something like this:
#right table table table { }
but doesn't seem to be working...
grr
#right table table table { } ...
If it is a table inside of a table inside of a table inside of id="right" then that will work. What you've shown is not that. You could try a sibling selector instead or this could have all been solved by using the generated ID or showing the code.
Don't use the generated ID,
Don't use the generated ID, this is bad practice. You will have to use one of the javascript/jQuery solutions above.
Hmm haven't read such a
Hmm haven't read such a confusing thread in a while!
And why is a generated ID so bad? I don't get why all the angst with this request why are the tables not each carrying a unique ID? and please no waffling about .ass.nut having to do things a certain way
It's bad practice because the
It's bad practice because the ID is automatically generated by .NET for reference purposes in the code-behind. This ID is unique but can change if the control is moved around so referencing it in the CSS could lead to problems later on IF it was moved around. All he has to do is use one of the jquery/js solutions above.
All of which tells me the
All of which tells me the mid-tier language is an inappropriate one for the purpose. The class and id tokens should be under the control of the front-end guy. Every time I think of ASP.Net, or whatever it's called this week, I get a feeling that my grandmother described as someone walking on your grave. :shudder:
cheers,
gary
I have to echo Gary's
I have to echo Gary's sentiments. That is exactly the reply I was expecting Jon and highlights something rotten in .Ass
Regardless a class can be added to each table? or not? If it can why can styles not be applied to the class. As much fun as jQuery is it's not really appropriate to use frontend scripting to work around issues caused by the backend language.
I do agree that it's not
I do agree that it's not ideal but if you move the control then you change the ID name in the CSS, of course this never happens after launch so it's really just a non-issue.
Of course the better solution is to either wrap the table in a fixed ID <div> or add a CssClass="" attribute to the table. A class can be appropriate in this case. You can also find the generated ID by using .ClientID for the control in question.
.NET 4.0 is supposed to have predictable IDs but this is yet another reason that I've switched to .NET MVC.
It is bad practice in my
It is bad practice in my opinion as it's just ANOTHER thing you have to remember to do if controls do get moved around and your right, this doesn't happen often but it does happen. It does also happen after launch of a website, what your saying basically is once something is launched a control is never moved, but they are as the master page can be switched for a new layout therefore changing the generated ID!
Of course adding a container or CssClass to each table is the obvious solution but he doesn't have access to the .aspx/.ascx files as stated in his previous post...
I don't really have access to the framework code...only the CSS files.
So, you can either use the jQuery solution (this is not normal practice, it's only because the guy doesn't have access to the page files) or reference the dynamically generated ID created for the table.
Regards.
I read that as "of course
I read that as "of course this never happens after lunch been sitting here puzzling what an earth difference having lunch should make on matters
jon19870 wrote: ... but he
... but he doesn't have access to the .aspx/.ascx files as stated in his previous post...
I don't really have access to the framework code...only the CSS files.
Yes, so ideal solutions go right out the window, right? I'd refuse such a job from the start. It's already giving me stress and I have no dog in this fight. lol
Hugo wrote: I read that as
I read that as "of course this never happens after lunch been sitting here puzzling what an earth difference having lunch should make on matters
ASP.NET is grumpy before lunch. Especially when we withhold her coffee.
Given the circs and that it's
Given the circs and that it's not possible to request some sanity in adding a few tokens to the tables, then yes the scripted approach is probably the only real feasible one, but it's a bad solution to a bad problem, simply not good all round, another case of shoot the mid tier programmers!
Quote: ASP.NET is grumpy
ASP.NET is grumpy before lunch. Especially when we withhold her coffee
Sounds like my ideal soulmate, generally attack coding early morning on two sips of coffee, by the third cup have deleted all up to that point and have started over suitably cafinated and calmed
Hugo wrote: ... shoot the mid
... shoot the mid tier programmers!
[SOLVED]
Of course after they've been
Of course after they've been made to sort it all out
Thinking of it now, how are
Thinking of it now, how are you meant to add the JavaScript/jQuery to the page when you can't access the page files. The only solution you have is to use the dynamically generated IDs.
jon19870 wrote: Thinking of
Thinking of it now, how are you meant to add the JavaScript/jQuery to the page when you can't access the page files. The only solution you have is to use the dynamically generated IDs.
Good point. The situations just keeps getting worse. It's kind of like getting stuck in a whirlpool. May as well just swim toward it to get it over with quicker.
Revisiting my previous
Revisiting my previous suggestion, consider the following:
table { border: 1px solid #f08; } table + table + table { border: 2px solid #80f; } table + table + table + table { border: 1px solid #f08; }
Take care with that. Unless
Take care with that. Unless all the tables have the same parent, they're not siblings. Guys who write asp.crp tend to overuse containers.
cheers,
gary
Verschwindende
Revisiting my previous suggestion, consider the following:
table { border: 1px solid #f08; } table + table + table { border: 2px solid #80f; } table + table + table + table { border: 1px solid #f08; }
I will try this V...thank you!!