admin管理员组

文章数量:1430562

<table>
    <tr>
        <td>Hello StackOverFlow</td>
    </tr>
</table>

Hi! I am new to html, can someone tell me what type of element is the word 'Hello StackOverFlow' inside the td tag? Is it a label?

<table>
    <tr>
        <td>Hello StackOverFlow</td>
    </tr>
</table>

Hi! I am new to html, can someone tell me what type of element is the word 'Hello StackOverFlow' inside the td tag? Is it a label?

Share Improve this question asked Apr 21, 2015 at 7:32 Ethyl CasinEthyl Casin 7932 gold badges17 silver badges34 bronze badges 9
  • 11 It is a text node. – Sami Kuhmonen Commented Apr 21, 2015 at 7:32
  • What he said. However, if you're referring to the <td> then that is a table data (I usually refer to it as a cell) . – Adam Kewley Commented Apr 21, 2015 at 7:33
  • it refers to table data (td) – Aru Commented Apr 21, 2015 at 7:33
  • 1 For styling with CSS: td { background-color: #000; }, unless you need something more specific – Adam Kewley Commented Apr 21, 2015 at 7:34
  • 1 If you want to change the textnode within a td then all the manipulations are done with the parent td. For example: td { font-size: 2 em; } – Adam Kewley Commented Apr 21, 2015 at 7:36
 |  Show 4 more ments

2 Answers 2

Reset to default 3

The element inside the <td> tag is a text node. You can't address it in CSS. If you want to style it, you either have to style the <td> tag or surround the text you want to style with a <span> element.

So to, e.g., style only the Hello:

<table>
    <tr>
        <td><span>Hello<span> StackOverFlow</td>
    </tr>
</table>

And in your CSS

span { font-weight: bold; }

Or whatever style you want to give it.

See also the answer to this related question.

Want to check the type of Hello Stackoverflow? Simpy check the td's content's nodeType

//Gave your td an id of 'td'
alert($('#td').contents().get(0).nodeType);

This will return 3. A nodeType of 3 means it is a text.

Here is an image of each nodeType:

w3schools on nodeType

本文标签: javascriptelement inside td tagStack Overflow