Reputation: 55
I have a table like this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr class="class1"><td>1</td><td class="Type">Type 1</td><td>Section 205</td><</tr>
<tr class="class2"><td>2</td><td class="Type">Type 1</td><td>Section 225</td></tr>
<tr class="class2"><td>3</td><td class="Type">Type 2</td><td>Section 115</td></tr>
</table>
I want to select a row which has an specific class and one of the colums contains an specific text. I know how to do the second thing with: $("td.Type:contains(Type 1)").parent()
but that would select the first and second rows, and I only want those which class is 2 (That is, the second one). I though I could do a selector inside a selector and I try with $("tr.class2 td.Type:contains(Type1)").parent()
which doesn't select anything at all, and $("tr.class2").$("td.Type:contains(Type1)").parent()
which isn't even a valid javascript command.
I was searching and I only could find how to get a sum of selections with $(selector 1, selector 2)
, which is not what I pretend.
Upvotes: 0
Views: 77
Reputation:
Pass a selector to the parent('.class2')
function
$('#result').append($("td.Type:contains(Type 1)").parent('.class2').attr('class'))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr class="class1"><td>1</td><td class="Type">Type 1</td><td>Section 205</td></tr>
<tr class="class2"><td>2</td><td class="Type">Type 1</td><td>Section 225</td></tr>
<tr class="class2"><td>3</td><td class="Type">Type 2</td><td>Section 115</td></tr>
</table><br/><br/><br/>
<div id="result">Result: </div>
Upvotes: 1