• Hi, I’m trying to do a simple test to understand how Advanced Custom Field works with Java script code.

    I created a Text Area Field and added this code below:

    <h1 id=”myH”></h1>
    <p id=”myP”></p>

    <script>
    /*
    The code below will change
    the heading with id = “myH”
    and the paragraph with id = “myP”
    */
    document.getElementById(“myH”).innerHTML = “JavaScript Comments”;
    document.getElementById(“myP”).innerHTML = “My first paragraph.”;
    </script>

    As a result on the front end of my website instead of seeing:

    JavaScript Comments

    My first paragraph.

    I am seeing this:

    /* The code below will change the heading with id = “myH” and the paragraph with id = “myP” */ document.getElementById(“myH”).innerHTML = “JavaScript Comments”; document.getElementById(“myP”).innerHTML = “My first paragraph.”;

    What am I doing wrong and how to solve it?

    I’d be very very grateful if you could help me over here,

    Thanks

    Marlos

    • This topic was modified 4 years, 2 months ago by marlosb.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • what are you trying to achieve?
    you need to render the fields with PHP and save it into JS variables.

Viewing 1 replies (of 1 total)
  • The topic ‘How to add Javascript Code to an Advanced Custom Field?’ is closed to new replies.