I have an array of elements (their ID's).
stage1check("htmlelement1", "htmlelement2", "htmlelement3");
These are input fields on a form, How can I change their background colour to red with jQuery? I have tried many times today but I always get an error.
jQuery(stage1check).each(function() {
console.log("else executed");
// highlight stage 1 red (required empty fields)
});
Scratching my head... how do I like jQuery("#" + stage1check[i]).css("background-color:red;");for each one?
css(). "This method can take either a property name and value as separate parameters, or a single object of key-value pairs." e.g..css('background-color','red')or.css({'background-color':'red'}). Alternatively, useaddClass()and define a CSS class withbackground-color:red;. Arguably, instead of using IDs, apply the same class to all elements and setbackground-color:redfor that class.stage1checkis an array, but the first code looks to imply that it's a function...?const stage1check = ["htmlelement1", "htmlelement2", "htmlelement3"];