[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to Overwrite TD Element Properties?

Posted on 2006-06-26
8
Medium Priority
?
484 Views
Last Modified: 2008-02-01
Hello,
I have a CSS file that sets TD peoperty for the whole page like this:

td{
font: 10pt Verdana;
}

I want to apply a different font and font size to only one particular table on this page without changing CSS TD set above. How can I do it if I know table's ID?

Something like this, perhaps, using JavaScript:
var mytable=document.getElementById("mytable");
mytable.style.fontFamily= "Arial";
mytable.style.fontSize= "8pt";

But this does not overwrite TD CSS set above. I need a way to apply above JavaScript to the TD element of the table. Please help!
0
Comment
Question by:Vadymus
  • 3
  • 3
  • 2
8 Comments
 
LVL 6

Expert Comment

by:inviser
ID: 16986010
why don't you you create a new css class, say:

td.new_class {
font: 10pt Verdana;
}

and then assign the particular td that class name like this:

<td class=new_class>...</td>

Otherwise if you still want to go the js route, make sure the js code comes after the css in the page, then it should work.
0
 

Author Comment

by:Vadymus
ID: 16986135
Great! But how can I assign these TDs to have "new_class" if I know TD's table ID? See, I do not want to do <td class=new_class>...</td> because in some cases this table is using default TD CSS.

So, can it be something like:
#tableId.td.new_class {
font: 10pt Verdana;
}

Thank you
0
 
LVL 6

Expert Comment

by:inviser
ID: 16986158
Sure thing, you would do it like this:

<td id=tdID>...</td>

<style>
#tdID {
font: 10pt Verdana;
}
</style>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16986315
here is the syntaxt if your table's id is "mytable":

table#mytable td {
  font-family: Arial;
  font-size: 8pt;
}
0
 

Author Comment

by:Vadymus
ID: 16986596
Your suggestions make my question answered almost completely.
Please, tell me the very last thing is it is possible:

If I have this (if syntax is correct):

table#mytable td.new_class {
  font-family: Arial;
  font-size: 8pt;
}

how can I tell JavaScript to apply it when I need (something like):

var mytable=document.getElementById("mytable");
mytable.className = "table#mytable td.new_class";
0
 
LVL 6

Expert Comment

by:inviser
ID: 16986657
I'm not sure I understand exactly what you are trying to do by the code you just posted. Could you elaborate a bit more?
0
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 100 total points
ID: 16986770
Sorry, i did not read the question with enough care.

You should set the class on the table:

var mytable=document.getElementById("mytable");
mytable.className = "someclass";

then use this CSS:

table.someclass td {
  font-family: Arial;
  font-size: 8pt;
}
0
 

Author Comment

by:Vadymus
ID: 16986814
GrandSchtroumpf offered this:

table#mytable td {
  font-family: Arial;
  font-size: 8pt;
}

By default, I have this:

td{
font: 10pt Verdana;
}

I want to use default all the time unless I specify GrandSchtroumpf's version. How do I specify it? That;s my question. I thought if I add a class to GrandSchtroumpf's version, then I can call it with JavaScript like this:

var mytable=document.getElementById("mytable");
mytable.className = "table#mytable td.new_class";

But will it work?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question