سؤال

How can I get value from table cell with css class ?

<html>
<head>
<title>Prototype examples</title>
   <script type="text/javascript" 
   src="/javascript/prototype.js">
   </script>
<script>

function showResult()
{
  var granica =  $('product-attribute-specs-table').getElementsByClassName('data')[0];
   alert("Returned value is : " + granica );
}

</script>
</head>

<body>

  <p>Click the button to see the result.</p>
  <br />


<table class="data-table" id="product-attribute-specs-table">
        <col width="25%" />
        <col />
        <tbody>
                    <tr>
                <th class="label">max beds</th>
                <td class="data">10</td>
            </tr>
                </tbody>
    </table>



  <input type="button" value="Toggle" onclick="showResult();"/>

</body>
</html>

Now I can get just object HTMl table cell element. How to get the element value? Adding .getValue() on the end won't help.

هل كانت مفيدة؟

المحلول

You are looking for innerHTML

$('product-attribute-specs-table').getElementsByClassName('data')[0].innerHTML;

نصائح أخرى

something very simple

$('product-attribute-specs-table').down('data').innerHTML;

or if you need multiple results

$('product-attribute-specs-table').select('data')[0].innerHTML;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top