Here, the code operates on anything that matches the #searchButton element:
jQuery("#searchButton")
If there is a searchButton on other pages, it will match it, soo you need to be more specific.
For example, on the homepage, the <body> tag will have the home class, here is my sites homepage body tag:
<body class="home blog logged-in admin-bar no-customize-support">
So to make it target only the search button on the home page, you could try something like this:
jQuery(".home #searchButton")
Alternatively, only enqueue the JS on that particular page, but the selector method is superior. Make sure there is only one element on the page with that ID as IDs need to be unique
Related Posts:
- Retrieve POST data from AJAX call
- WordPress Ajax always returns a 404 error
- problem with ajax and the path to the php page
- How to use wp_localize_script in a WordPress page other than functions.php?
- Real time Duplicate title check
- Load custom field value into div with AJAX
- Jquery ajax to custom php file: returning blank data
- Update WordPress Custom Field with AJAX on cached page
- Looking for a better way to handle an ajax script that pulls in post data on click
- Can’t use get_results() in ajax query
- Problem with WordPress Ajax form
- Display notification only once
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Passing jQuery value using Ajax to a page template
- ajax_object is not defined when ajax calls the function
- Returning a value from a PHP page
- Why is this Ajax not working?
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Use ajax from function.php
- Ajax return code 400
- doing an ajax request always outputs 0
- Woocommerce add to cart quantity buttons with AJAX
- class click counter save number
- AJAX request status 200 but no actual “response”
- wordpress count link clicks by ip address
- ajax, right way to do it and make it works?
- Ajax load more posts with multiple tax query
- WordPress Sending data to Ajax with select option
- WordPress ajax doesn’t display object method on jQuery .change() function
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Ajax date_query not working past the first iteration
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Save Search System
- populate form fields in a loop with ajax
- dynamic dependent select dropdown
- Setting value of session with Ajax not working
- [jQuery]Adding shortcode
- Display parent and child taxonomies in separate drop down select fields
- Plugins not working on AJAX requests
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- WordPress admin-ajax.php 400 bad request
- Ajax contact form return 0
- AJAX – Returning Two JSON Objects with One PHP Function
- Pull GetOption() variable into jQuery dynamically created html
- Add Ajax Hooks and Call from Custom Template PHP
- WordPress Ajax Always returning 0
- How to keep track of when a vote is cast?
- WordPress plugin admin page – using WordPress function in linked php file
- A $_POST should occur when submit form but is not?
- My jQuery Ajax form submit is still refreshing page?
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- Output votes to div dynamically in wordpress
- Get uploaded image and attach it to the new post
- Admin-ajax php not working on new wordpress version
- Proper way to use WordPress function with AJAX PHP file
- Live search from database table
- Add a counter for mouseovers (custom field)
- Accessing an API with jQuery and AJAX
- How to set variables with AJAX request to use in another function in WordPress
- Search Ajax Call – Use Form Data in Response
- Why does PHP called with Jquery AJAX not allow additional php code to be added?
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Database entry removed on browser refresh, Ajax PHP jQuery
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- How do I call a value from the datase using ajax
- Ajax result show in console if is called outside function and not showing in array
- Where to add my PHP codes for AJAX Jquery to work?
- How to change PHP variables with AJAX request in WordPress
- How to use wp_ajax_set_post_thumbnail?
- Can’t make lazy load for my site, help!
- How to reload a php script, using AJAX and jQuery
- wp_ajax_ 400 Bad Request
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- Input field duplicates on form submit by jQuery
- How to call a function from functions.php with ajax?
- Custom theme admin-ajax.php 400 (Bad Request)
- number of posts with “Load More”
- Find the method which AJAX GET calls
- Ajax not updating to database
- WordPress 404 when using AJAX to call php function
- how use php query in AJAX jquery
- Ajax Load more CPT via shortcode
- Submitting my form to the database and then redirecting to payment site
- Pass the updated value of aid from form using ajax
- ajax form with multiple submit buttons and values
- Add php function into .js file (for tinyMCE button)
- best way to communicate between php and jquery/javascript
- Fatal error: Uncaught Error: Call to undefined function wp_nav_menu()
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- Why not showing all post by default in my jquery filter
- Load Meta box value into div AJAX [duplicate]
- ajax problems on loading page [closed]
- Help with AJAX request
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- custom AJAX filtering logic and outputting results into an Elementor Loop Grid widget