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


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’)

    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

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.