Support

Account

Home Forums Front-end Issues get access to true/false field in JS to manipulate a class

Unread

get access to true/false field in JS to manipulate a class

  • Hi! Im new to acf fields. Im really struggling with a function.

    So I have a post and I have created a true/false button as a custom field.
    Im trying to use the value (true or false) to add a class to an element. The problem is this element is on a page, not in the post where the custom field is located.
    I would like to access the custom field in my javascript. I tried giving my custom field a class(customField) and then in my .js file trying to access it by:

    var customButton = $(‘.customField’)
    console.log(customButton);

    This just consoled empty. I want to do something like:

    $(function() {
    var customButton = $(‘.customField’)
    var element = $(‘someElement’);
    if (customButton){ // meaning if the button is true
    $element.addClass(‘classname’);
    }
    });

    my .js file doesnt know what the customField is and its not working.
    Does someone have some suggestions on how to go about on this?
    Reeeeally appreciate it.
    Im sorry if the forum is incorrect, I wasn’t sure.

Viewing 1 post (of 1 total)

The topic ‘get access to true/false field in JS to manipulate a class’ is closed to new replies.