Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

I want to change all <input> with a name = "Player_Name" to (css) "background:blue;" JavaScript

  • SOLVED

I want to change all <input> with a name = "Player_Name" to (css) "background:blue;"

Answers (2)

2018-11-19

mohitseth answers:

you can write the following CSS, you don't need javascript for it:


input[name="Player_Name"] {
background: blue;
}


If you really want to do in js, you can do following:


const inputs = document.querySelectorAll('input[name="Player_Name"]');

inputs.forEach((element) => {
element.style.backgroundColor = 'blue';
});

2018-11-19

Arnav Joy answers:

if you need js code you can try this

$('.input_id').change(function(){
if ($(this).val() == 'Player_Name'){
$(this).css('background','red');
}
else{
$(this).css('background','');
}
});


where input_id is the same class added to input element