Reputation: 34573
Looking at this jQuery example, how can I modify the code so that it only changes the color of the cell if the value of the submit button in that cell is a certain value.
i.e.-
var submitEl = $("td :submit")
//Only do the below if the submit buttons value is "XYZ"
.parent('td')
.css({background:"yellow", border:"3px red solid"})
Upvotes: 3
Views: 208
Reputation: 20446
select only the elements that have the value you want:
var submitEl = $("td :submit[value='XYZ']")
Upvotes: 2
Reputation: 17638
you need a each loop I think this is what your trying to do
$("td :submit").each(function(){
if ($(this).val()== "XYZ"){
$(this).parent('td').css({background:"yellow", border:"3px red solid"});
}
});
EDIT
using better selector eliminates if statment
$("td:submit[value='XYZ']").each(function(){
$(this).parent('td').css({background:"yellow", border:"3px red solid"});
});"
Upvotes: 2
Reputation: 413826
var submitEl = $('td :submit').filter(function() { return $(this).val() == "certain"; });
You can check for the value in the selector, but it may lead to quoting headaches (depending on the value) and also it may not be quite as fast (though that's rarely a serious concern).
Upvotes: 2