to be able to identify a specific “post” you need to have some unique attribute in its HTML. Usually the easiest thing to do is to use the post id as part of the id attribute (in your case maybe something like overlay{$post_id}). I personally started to prefer to use data- style attributes instead but for this use case the difference is more of esthetics than anything else.
Now that you have everything unique (and maybe even instead of doing that at all), either use a common class on all the “posts” and have a handler for click on elements with that class (easy with jQuery), or add a click handler on the containing div instead of the elements, and in the handler look at the event properties to find out which “post” was actually clicked.
Related Posts:
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Is it possible to use the featured image of a page as a css background without inlining?
- Minify HTML, CSS, JS with PHPWee?
- Archive dropdown styling not applied
- An unwanted inline style is added to my body tag
- Show post in slider
- Slider loading issue
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Incorrect MIME type for assets with Valet
- How does wp_enqueue_scripts work?
- Add Codepen animation as Preloader to WordPress
- trouble with page_id & highlighting current page
- wordpress admin plugin menu custom css
- How to add drag and drop functionalities to a div inside option panel
- Removing WordPress Footer -without access to PHP code?
- How to Change CSS Colors from Custom Plugin Settings Page
- Link to page with posts of specific type
- How to add new CSS file to new PHP file
- How to sort posts by active category in WordPress?
- Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)
- Add other class content with reference class value
- Run do_shortcode on php template using JS function
- How do I integrate vanilla Javascript to a wordpress website?
- Google CSE Malfunctions via Chrome/Safari on Mobile When Clicking on Either Search Icon/Menu Icon. How to Make Google CSE Default Theme Search
- I have a lot of JavaScript erorrs after SSL someone can help me?
- WordPress Slider is not working
- register dependency css and js inside a plugin class
- Bring Font Awesome icons inside menu A tags
- custom field – changing an element or background of id div – different versions not working
- Target a specific container to style on WordPress storefront theme
- Where to find the html for WordPress site? [closed]
- Trying to customize wordpress drop down categories
- How to create and add js and css file when server is not on my PC?
- Embed dynamic media query in a Gutenberg block
- JavaScript, best way to use data from the loop
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- if file_exists not working with wp_enqueue_style
- Unable to set right time in admin and frontend template
- Easiest way to show total number of subpages
- Javascript code inside “” in core WordPress files .php
- Create custom blocks for bootstrap
- Want to create Child theme, but already edited Parent theme css files and some php files
- Switching between custom templates in a post type of the admin menu
- Use template for posts with a particular category grandparent
- Run a Parallel PHP Application with WordPress
- Click loads template via ajax
- Using PHP to toggle stylesheet and header image, set in cookie
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- How to display a value from a radio button in the options menu in wordpress
- 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]
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- Get/Set wp.customize.previewer.previewUrl
- javaScript in section of WP API
- How should I best target dynamically served content?
- Blank space at beginning of tag?
- Different background-image by category
- Style every second widget?
- Placing the_content inside shortcode not working
- admin-ajax.php responding with 0
- Using wp_localize_script to store the template url into a variable to use in JS
- Link to file in plugin directory from wordpress template?
- How to scale image with equal width and height without distortion?
- How can the plugin directory path be returned into ?
- Password protecting content in custom template
- Add a Different CSS Class Into The Body Tag of Different WP Pages
- How can I add tinymce editor in WordPress with jQuery?
- How to speed up admin-ajax.php in wordpress
- How to override wp-admin styling
- php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)
- JQuery not working on WordPress Admin page [closed]
- Customizer Show/Hide
- Page Reloads Before AJAX Request Finishes
- wp nav menu: add attributes to menu items [duplicate]
- Add a Second Menu to a theme that only support 1 menu
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Custom excerpt function re-factoring
- WordPress override bloginfo variable
- How to make custom total price reactive in navigation
- Adding tawk.to code just before body tag on functions.php file
- Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
- How do I fetch all comments per post via WP REST API?
- Put CSS inside a PHP file and include it the right way
- Deregistering a script in WordPress seems impossible
- Slide in Panel WordPress Post
- Sending jsPDF documents to the server
- Shortcode content output but not in correct place
- How to prevent those PHP variables from being cached on WordPress?
- How to display user nickname (not display name) in PHP template?
- Custom Template 404 for specific custom post type
- Ajax return code 400
- How to properly insert a link to a template in WordPress?
- How can I add an alert (like the old javascript alerts) to my WP page?
- Pass PHP variable to JavaScript without inline JS
- Displaying theme options in css
- How can I output a php value into a JS file within WordPress?
- Custom field value not saving when it contains a URL?
- Problem adding class to body_class