Yeak Yeak - 4 months ago 30
HTML Question

jquery find all hidden input fields with specific class name

I have a couple of table rows and tables with hidden input fields and values. What i need to do is loop through all the hidden input fields and find a specific field where the class = 'something' and value = something and go up to the

<td>
of that input field and change the background color.

$('input:hidden').each(function(){
if( $(this).find(".id_schedule_hours") && $(this).val() == 1) {
console.log('here')
}
}

Answer

.each() is not necessary; you can use attributes selector, .closest()

$("input:hidden[class='something'][value='something']")
.closest("td").css("backgroundColor", /* color */)
Comments