1

i want to find value in row of table. Sample , i have a this case

    $("tr[id*='row']").each(function (i, el) {
            //if($this.value() >10)
            //console.log('This value in cell is: ' + this.value);
        });
<div id='div1'>
    <table border='2px'>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
        </tr>
    </table>
    <table border='2px'>
        <tr>
            <td>5</td>
            <td>6</td>
        </tr>
        <tr id='row' style="background-color:yellow; color:red">
            <td>7</td>
            <td>8</td>
        </tr>
    </table>
    <table border='2px'>
        <tr id='row' style="background-color:yellow; color:red">
            <td>9</td>
            <td>10</td>
        </tr>
        <tr>
            <td>11</td>
            <td>12</td>
        </tr>
    </table>
    <table border='2px'>
        <tr>
            <td>13</td>
            <td>14</td>
        </tr>
        <tr id='row' style="background-color:yellow; color:red">
            <td>15</td>
            <td>16</td>
        </tr>
    </table>
</div>

In this case above , i want to compare and show the value in cell, which more than 10, but i confused in define the value in cell. Mabe you can give me adviced for this case .

2 Answers 2

2

Use find for td values.

$("tr[id*='row']").find('td').each(function(i, el) {
var val = $(this).text();
if (val > 10)
  console.log('This value in cell is: ' + $(this).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='div1'>
    <table border='2px'>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
        </tr>
    </table>
    <table border='2px'>
        <tr>
            <td>5</td>
            <td>6</td>
        </tr>
        <tr id='row' style="background-color:yellow; color:red">
            <td>7</td>
            <td>8</td>
        </tr>
    </table>
    <table border='2px'>
        <tr id='row' style="background-color:yellow; color:red">
            <td>9</td>
            <td>10</td>
        </tr>
        <tr>
            <td>11</td>
            <td>12</td>
        </tr>
    </table>
    <table border='2px'>
        <tr>
            <td>13</td>
            <td>14</td>
        </tr>
        <tr id='row' style="background-color:yellow; color:red">
            <td>15</td>
            <td>16</td>
        </tr>
    </table>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

Dear sir, you forget compare with 10 , if more than , show this.value
1

$(document).ready(function(){
    $("tr[id*='row']").each(function () {
		var td = $(this).find("td");
		var countdeeptd = td.length;
		td.each(function(i,el){
			if(td.eq(i).text() > 10)
				console.log('This value in cell is: ', td.eq(i).text());
		});
	});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='div1'>
    <table border='2px'>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td>4</td>
        </tr>
    </table>
    <table border='2px'>
        <tr>
            <td>5</td>
            <td>6</td>
        </tr>
        <tr id='row' style="background-color:yellow; color:red">
            <td>7</td>
            <td>8</td>
        </tr>
    </table>
    <table border='2px'>
        <tr id='row' style="background-color:yellow; color:red">
            <td>9</td>
            <td>10</td>
        </tr>
        <tr>
            <td>11</td>
            <td>12</td>
        </tr>
    </table>
    <table border='2px'>
        <tr>
            <td>13</td>
            <td>14</td>
        </tr>
        <tr id='row' style="background-color:yellow; color:red">
            <td>15</td>
            <td>16</td>
        </tr>
    </table>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.