-3

I have a html file:

<html>
<body>
<div id="1">
<table>
<tr>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="yes"></td>
</tr>

<tr>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
</tr>

</table>
</div>



<div id="2">
<table>

    <tr>
    <td><input giveBorder="yes"></td>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="yes"></td>
</tr>

<tr>
    <td><input giveBorder="yes"></td>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
</tr>

</table>
</div>



<div id="3">
<table>
<tr>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
</tr>

<tr>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
    <td><input giveBorder="no"></td>
</tr>

</table>
</div>
</body>

I'm iterating through all div's and now I need to search if entire table contains particular attribute and value. I need to search for giveBorder="yes" in whole table. If it any of the field contains that then I need to set border for that table and set border colour to red using jQuery.

After iterating through div I tried

var par = $(this).parent('table');
if(par.has('giveBorder="yes"').length === 0) {
    console.log("table has to be set red border");
}

How can I search for that attribute in enitre table, and set css for it?

FZs
  • 16,581
  • 13
  • 41
  • 50
newbie 22
  • 21
  • 5
  • Possible duplicate of [jQuery find element by data attribute value](https://stackoverflow.com/questions/21756777/jquery-find-element-by-data-attribute-value) – Anurag Srivastava Jul 30 '19 at 13:03

2 Answers2

0

You have the wrong selector try the attribute selector:

var par = $(this).parent('table');
if(par.has('[giveBorder="yes"]')) {
console.log("table has to be set red border");
}

or

var par = $(this).parent('table');
if(par.find('[giveBorder="yes"]').length) {
console.log("table has to be set red border");
}
madalinivascu
  • 32,064
  • 4
  • 39
  • 55
0
   $("input[giveBorder=yes]").parents("table").css("border", "1px solid red");
  • You should explain a little more your answer. Just from this, it's really hard to tell how or why your answer works. – ifconfig Jul 30 '19 at 18:11