D
D
damorin2013-12-22 21:47:32
JavaScript
damorin, 2013-12-22 21:47:32

How to work with a table using Jquery?

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  <style type="text/css">
  table .c { color: red; } 
  .a .c { color: green; }
  </style>
</head>
<body>
<table id="t">
    <tbody>
        <tr>
            <td class="c">Текст</td>
        </tr> 
    </tbody>
</table>
</body>
</html>


Problem number 1 I can’t get to the content using this construct :

$("#t").find("td").eq(1).text()

It says that this element does not have a find method ...

Who can’t understand what the problem is ...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eugene Obrezkov, 2013-12-22
@damorin

Is jQuery itself connected exactly? What happens if you change the table id to another one? eq(1) is incorrect because all elements are counted from zero. Therefore, in this situation, .eq(0) will be correct.

P
pingo, 2013-12-22
@pingo

always, when generating a table, I assign classes to cells, at least those that need to be worked with later on the client side. and the code is easier to get and you don’t need to perform terribly heavy .find()
if it’s .find() then within the framework <tr>and not the entire table

D
demimurych, 2013-12-22
@demimurych

$("#t td:eq(0)").text();
$("#t td:first").text();

I
Ivan Belenkov, 2013-12-23
@IoannGrozny

.eq(1) is the second element, and you only have one. numbering starts from zero.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question