How to change this jQuery: provide an example of a selector?

Looking at this jQuery example, how can I change the code so that it only changes the color of the cell if the Send button in this cell is a specific 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"})
+3
source share
4 answers
$("td input[value='SomeValue']:submit")
+4
source
var submitEl = $('td :submit').filter(function() { return $(this).val() == "certain"; });

You can check the value in the selector, but this can lead to quoting headaches (depending on the value), and it may not be as fast (although this rarely causes serious concern).

+2
source

, :

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

, , ,

  $("td :submit").each(function(){
   if ($(this).val()== "XYZ"){
     $(this).parent('td').css({background:"yellow", border:"3px red solid"});
   }
   });

, , statment

  $("td:submit[value='XYZ']").each(function(){
     $(this).parent('td').css({background:"yellow", border:"3px red solid"});
  });"
+2

Source: https://habr.com/ru/post/1740988/


All Articles