What you can do is pass the variable from outside that .js
file, like this:
// index.php <div class="row"> <div class="small-12 columns"> page content </div> </div> <script>var test = '<?php echo $variable; ?>';</script>
and then reference that variable the same as if you defined it within that .js
file (mind the potential scope issue).
Related Posts:
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- is there something like isset of php in javascript/jQuery?
- How do I refresh a DIV content?
- Only on Firefox “Loading failed for the script with source”
- Ajax success function
- AJAX not Working with php as supposed
- Open image gallery on link click
- Uncaught ReferenceError: $ is not defined?
- jQuery document.createElement equivalent?
- Toggle show/hide on click with jQuery
- jQuery .on(‘change’, function() {} not triggering for dynamically created inputs
- How to create a jQuery function (a new jQuery method or plugin)?
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Bind function
- Scroll to an element with jQuery
- Uncaught TypeError: Cannot read property ‘length’ of undefined
- Check if element exists in jQuery
- Checking a Url in Jquery/Javascript
- Uncaught TypeError: $.post is not a function
- When and why to ‘return false’ in JavaScript?
- Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
- querySelector vs. getElementById
- How to generate a simple popup using jQuery
- Jquery swipe left or right on mobile
- How to move an element into another element?
- document.getElementByID is not a function
- Moment js date time comparison
- How to create a JQuery Clock / Timer
- bootstrap-datetimepicker for bootstrap 4
- Access Control Request Headers, is added to header in AJAX request with jQuery
- How to set ‘X-Frame-Options’ on iframe?
- How do I check if string contains substring? [duplicate]
- explode string in jquery
- Play an audio file using jQuery when a button is clicked
- How can I get the last character in a string?
- document.getElementsByClassName().innerHTML always returns “undefined”
- Jquery button click() function is not working
- How to define Global Arrays?
- Why is this jQuery click function not working?
- Disable Chrome strict MIME type checking
- How to uncheck a radio button?
- Phone mask with jQuery and Masked Input Plugin
- JQuery get all elements by class name
- Attaching ‘onclick’ event to D3 chart background
- How do I check whether a checkbox is checked in jQuery?
- jQuery count child elements
- How do I check if an element is hidden in jQuery?
- SyntaxError: Unexpected token C in JSON at position 0 – Ionic 2 Http GET request
- jQuery equivalent of querySelector
- Convert normal date to unix timestamp
- jQuery replace one class with another
- Clearing my form inputs after submission
- Changing the image source using jQuery
- Get class list for element with jQuery
- Reload an iframe with jQuery
- Convert array to JSON
- How to disable scrolling temporarily?
- How to manage a redirect request after a jQuery Ajax call
- How do you remove all the options of a select box and then add one option and select it with jQuery?
- Get the Highlighted/Selected text
- How to get the children of the $(this) selector?
- window.onload vs $(document).ready()
- jQuery scrollTop() method not working
- FormData append not working
- Print a div content using Jquery
- how to write javascript code inside php
- Uncaught TypeError: Cannot read property ‘toLowerCase’ of undefined
- How can JavaScript save to a local file?
- How to go to a URL using jQuery?
- How to close a window using jQuery
- jQuery .animate() not working
- Pass media upload value to input field
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- Using shipped version of jquery
- Adding JavaScript to a WordPress website
- AJAX request status 200 but no actual “response”
- wordpress site | All-in-one-cufon IE Issue
- Save Search System
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- How do I Import / Upload Files with jQuery AJAX?
- is_page_template() written in jquery/javascript
- wordpress add_action() issue in ajax call
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Can’t get rid of JQMIGRATE: Migrate is installed, version 3.3.2. Manually updated all the libralies and site. 5.8.2
- Script only works on wordpress home page & only when Jqurery is aded using
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- Error on clicking ‘Screen Options’ tab only at Products-related editor screen(s) and for specific user
- WordPress load javascript file if something… (after the page is loaded)
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- How can I correctly POST to a WordPress page?
- JSON Object Value Show Undefine
- Adding jquery using php function
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- notify users when changed database
- Access jQuery tabs from primary menu while adding/removing class on tab container elements (accessing diff. tabs/tab content via primary menu items)