I have some php that adds a class (bg-success) to a <td>
if its value is used for something else. In every <td>
is a text input. How can I make the input required if the class of the td is "bg-success"?
<tr>
<td class="border text-center">
<input type="text" name="1">//not Required
</td>
<td class="border text-center bg-success">
<input type="text" name="2">//needs to be required
</td>
<td class="border text-center bg-success">
<input type="text" name="3">//needs to be required
</td>
...
I have tried a few variations of this:
$(document).ready(function() {
var parents = document.getElementsByClassName("bg-success");
for (var i = 0; i < parents.length; i++) {
var parent = parents.item(i);
parent.find(">:first-child").attr('required', '');
}
});
It hasn't liked any version I have tried and maybe I'm not even close to correct. It doesn't like whatever I put after parent or parents.item(i)
.
I know I could move the class to the input but I like it being more like a border.
Full transparency, this is my first coding project and I am sure that I am doing everything the hard way. This site has helped me figure out a lot of things. Thanks in advance.