• Hi
    how can we call pure JS code inside the description field? The description is printed out as AJAX response, and that’s probably the reason our JS is not working in the description field.
    Example:We have tabs in the description field, taking code from
    https://www.w3schools.com/howto/howto_js_tabs.asp

    Unfortunately this is not working. The JS is not changing the styles.

    Simply, how do we execute:
    <script>alert(‘it works’);</script>

    Thank you.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    You can’t include JS code in the description field like that. The returned data is placed in a underscore template and simply printed, so it’s wont execute.

    What you can try is this ( assuming you want to have the tabs in the desc field ). Only include the HTML structure in the content. Then load a custom js file from the functions.php with wp_enqueue_script, and in that file use ajaxComplete to run JS code after the search is finished.

    This should allow you to make the tabs work in the description field as expected, but I didn’t test it.

    Thread Starter rombaaa

    (@rombaaa)

    Thank you for a fast reply. Unfortunately, this doesn’t work. The js is enqueued and no testing alert msg appears.

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Maybe set a lower priority for the loading of the enqueued script?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘javascript in description via ajax call’ is closed to new replies.