The correct way to do this is to:
$('#upload-background-image-one').click(function() {
formfield = $('#background-size-one').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
// Take the selected image and insert only the src path into the text field.
window.send_to_editor = function(html) {
img_url = $('img', html).attr('src');
$('#background-size-one').val(img_url);
tb_remove();
}
return false;
});
because when you click on a button you instantiate a call back function you can do everything in that function. Scope is then tied to that fucntion
Related Posts:
- pass object/JSON to wp_localize_script
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- How to Change CSS Variable value in Theme Customizer Live Preview
- How to correctly add JQuery in a WP theme?
- Including Javascript options
- jQuery not available to other scripts
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- My jQuery is enqueued properly. So why isn’t it working?
- How to enqueue scripts properly with ES6 webpack?
- change background image on scroll
- Set start page depending on screen width [closed]
- Theme now uses require.js and enqueue script no longer works
- can’t add EVENT LISTENER to a element
- jQuery Snippet Not Working on WordPress Site [closed]
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- How to add material design css in wordpress and woocommerce
- Use second time navigation.js in underscores [closed]
- WordPress Media Uploader in page template (On Front-end)
- Theme Javascript.php Overwritten Nightly [closed]
- Menu jumping when calling it via PHP
- How to get javascript slider to work! [closed]
- Limit filetype and wp media
- Theme Customizer not loading JS for live preview
- Post thumbnail to append post content via ajax click event
- Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?
- Using page-id-{ID} from body_class() in local dev, versus live staging
- Custom theme, contact form 7 & fast secure form doesn’t work
- Enqueued JavaScript is not working
- In creating a theme, how can i allow a user to change an image outside post/page content?
- Javascipt issue on custom theme
- How To Pick Custom Size Of Uploaded Image In Theme Via the_post_thumbnail();?
- How to make javascript work on theme options page
- How to register and enqueue JavaScript files without breaking plugin dependencies?
- wp_enqueue_script not working?
- JQuery undefined and Stylesheet loads in bottom along with js files
- Weirdness in jQuery supplied with WordPress
- How can I wrap all blog posts image with
- wp.media issue with selected image
- White screen when attaching css to function.php
- WordPress theme resource won’t load over VPN
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- pass wordpress template directory into ajax url call
- theme-independent CSS/JS files
- jQuery from parent theme loaded with many other scripts in a single min.js file
- Javascript development in Custom Themes
- WordPress creating images if uploaded image is greater than 960px on one side?
- Callback Function Not Firing On Selection In Media Uploader
- Trouble in enquing all js files under certain directory
- add jquery file if a certain page is included
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- How do I implement jPanelMenu?
- loading javascript after jquery is loaded
- Theming media inserts
- MapPress Easy Google Map in Jquery Tabs Problem
- enqueuing external and internal js and css in wordpress did not work with owl.js animate.css
- I don’t think WordPress is loading jquery or bootstrap js
- getBoundingClientRect() showing different values on load vs scroll
- wordpress script_loader_tag in function.php
- How to diagnose wp-env environment problem
- how can i remove js file from my footer in wordpress
- How to properly use AWS SES for a contact form?
- Embedding CodePen Calorie Script – jquery error
- How to load jQuery with Ajax in WP version 5.3.2?
- Ajax Comment Upvotes – Votes don’t always register
- Infinite scroll without plugin using ajax
- How to make the media library searchable by image title
- Why does my media selection script write to ONLY the first input field?
- Customizer Image-Picker Preview Not Working
- Does any JavaScript file load automatically for index.php file?
- how to add jquery to wordpress
- How to load mediaelement.js in theme template?
- jQuery conflict in WordPress, works fine in HTML
- Flexslider not working for my custom theme WordPress
- FitVid not working for iframes on particular theme install
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- WordPress custom jquery not found
- Can’t attach Javascript to theme
- Passing a location-dependent array via wp_localize_script within a shortcode
- enqueue script if page is not equal to
- wp_deregister_script was called incorrectly
- Paginated WP_Query doesn’t return 404’s, even when posts don’t exist
- Using wp_enqueue_script with social media buttons?
- How to convert that page to a wordpress template? [closed]
- wp_enqueue_script causes page to vanish
- WordPress Subpages Fancybox Trouble
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- What is The Best Way to Make Parallax header effect for wordpress theme ?? pure CSS or using JavaScript? [closed]
- Javascript as Jquery Function Call?
- WP site makes mobile browser crash for high memory usage
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- How to get the value entered in the input field in wordpres
- How react js and other Javascript Technologies works on WordPress plugin?
- When trying to run build script with gutenberg (with SVG import) – Error: Plugin name should be specified
- Is there any halfway decent documentation on the wp.media JS class?
- WordPress Includes mejs 404 error
- Smooth Scrolling Animation of Image Between Two Containers (Elementor) Using JavaScript and GSAP
- How to add group-row to InnerBlock template?
- Javascript localization doesn’t load. How to Internationalize javascript without plugin?