If an input is in focus or has a value, I want to add a class to all inputs parent .field div. For example on the product page review form or on the checkout page shipping form. If the input is in focus I would add an "active" class and if the input has a value I would add the class "hasavalue."

When I try to use jquery, nothing happens on the product page review form inputs or on the checkout page inputs.

Here's the jquery I am using:



    $('.field input').focus(function () {
    }).blur(function () {

    $('.field input').blur(function(){

        if ( $(this).val() ) {
        } else{



Do I need to use knockout? If so, how can I translate this simple jquery to work with all inputs in Magento?

1 Answer 1


try this:

function() { 
var spinner = $(this),
 input = spinner.find('input[type="your inpur type"]'); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.