T.T.T.
T.T.T.

Reputation: 34573

How do I modify this jQuery :submit selector example?

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

Answers (4)

dnagirl
dnagirl

Reputation: 20446

select only the elements that have the value you want:

var submitEl = $("td :submit[value='XYZ']") 

Upvotes: 2

mcgrailm
mcgrailm

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

Pointy
Pointy

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

Darin Dimitrov
Darin Dimitrov

Reputation: 1039110

$("td input[value='SomeValue']:submit")

Upvotes: 4

Related Questions