Link to each topic's corresponding image

The issue at hand is that only the image of the latest post is being displayed. Every link should show the image corresponding to its respective post.

jQuery(document).ready(function() { 
var link = $('h2.topic-title > a').attr('href');
jQuery.get(link, function(data) {
    imglink = jQuery('.wrap .post .entry-content div img', data).attr('src');
    jQuery('h2.topic-title > a').after('<div class="verimg"><img src="' + imglink + '" /></div>');
});});

My intention is for each post to have its own image displayed next to the link. However, it seems to be showing the same image for all posts.

Answer №1

It seems like there may be a problem with the way you are using your selectors.

$('table > tbody  > tr > td > h2.topic-title > a')

There is a more efficient way to select an anchor tag within a table. You can simply use

$('h2.topic-title > a')

Alternatively, you could consider adding a custom class (such as .img-post) to each anchor element you want to target and then selecting them with $('.img-post')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Most left-aligned icon on the left, most right-aligned icon on the right, and evenly spaced icons in between

Imagine a scenario where you are presented with a questionnaire that allows you to respond using a slider (HTML range element). Below the div containing the range selector (slider), I have arranged icons that need spacing. The icon on the far left should ...

Combining Two Arrays Based on Unique Identifier

Seeking guidance on enhancing this method to eliminate the need for a workaround. I have two separate Object Arrays containing JSON data. The first array consists of all dates within a specific range, while the second array is derived from a SQL query, po ...

It appears that jQuery Tooltips are not heeding the delay settings as intended

Is there a way to make the delay parameter work in displaying a tooltip on rollover? I am attempting to slow down the fadeOut, but the delay option doesn't seem to be working. I have found that using the delay parameter results in leaner code compare ...

Ensure that the dropdown <select> remains open even while filtering through options

I am currently working on implementing a mobile-friendly "filtered dropdown" design: https://i.sstatic.net/SYjQO.png Usually, a <select> control remains closed until the user clicks to open it. Is there a straightforward way to keep it always open ...

What is the best way to sort through this complex array of nested objects in Typescript/Angular?

tableData consists of an array containing PDO objects. Each PDO object may have zero or more advocacy (pdo_advocacies), and each advocacy can contain zero or more programs (pdo_programs). For example: // Array of PDO object [ { id: 1, ...

Avoid sudden page movements when validating user input

After successfully implementing the "Stars rating" feature from https://codepen.io/462960/pen/WZXEWd, I noticed that the page abruptly jumps up after each click. Determined to find a solution, I attempted the following: const labels = document.querySelect ...

Transforming the output of a MySQL query into a JSON format organized like a tree

This question has been asked before, but no one seems to have answered yet. Imagine a scenario where a MySQL query returns results like this: name | id tarun | 1 tarun | 2 tarun | 3 If we were to standardize the JSON encoding, it would l ...

Angular.js: Oops! Looks like the 'MyApp' module is missing

Can anyone help me with using this plunk locally on my machine? I've been trying to run it with the local Python server or http-server, but I keep encountering this Error message: Uncaught Error: [$injector:modulerr] Failed to instantiate module myAp ...

Obtain the latest NPM package versions

I am currently seeking a way to compile a comprehensive list of all major versions that have been released for a specific NPM package. By utilizing the following API link, I can retrieve a list of available versions which includes both the major and exper ...

When you click on the poster image, will the HTML5 video start playing?

How do I create an HTML5 video where clicking anywhere on the poster image starts playing the video without using flash? I can't seem to find a way to do this and would greatly appreciate any help. ...

Determine the final date by taking into account the initial date and selecting the quantity of packages from a dropdown menu in CakePHP

Is it possible to calculate an end date based on the user selecting a start date and a specific number of packages? For example, if I choose a silver package and a start date of January 1st, could the date field automatically update to show a date that is ...

Navigating additional information in D3 Node Link Force diagram

Recently delving into the world of D3, I have been pleasantly surprised by its capabilities and decided to experiment with the Directional Force Layout. My Objective Initially, I successfully created a json object using a for loop to prepare my items for ...

Middleware in Express.js Router

In the following code snippet, I am aiming to limit access to the 'restrictedRoutes' routes without proper authorization. However, I am encountering an issue where 'restrictedRoutes' is affecting all routes except for those within the & ...

Tips for updating comments using ajax technology

I need to implement AJAX in order to update the page automatically whenever a new comment is added, eliminating the need to manually refresh the page. I have attempted to achieve this by adding a section of code but it's not working as expected. Even ...

Ensuring the responsiveness of CSS and jQuery animations

Issues Encountered: The animation I implemented lacks responsiveness as images and text tend to move around and appear disproportioned on smaller screens. The .moveup class fails to animate properly despite numerous attempts to set up CSS transitions cor ...

Steps to store chosen option from dropdown list into a database's table

I am currently populating a dropdown list in my PHP file by fetching data from a database. Here is the code snippet: <script type="text/JavaScript"> //get a reference to the select element var $select = $('#bananas'); //reques ...

Is it possible to implement an automatic scrolling functionality in this code snippet?

https://codepen.io/hexagoncircle/pen/jgGxKR?editors=0110 Stumbled upon some interesting code to tinker with and came across this piece. Attempted to search online for solutions, but my grasp on React (or maybe Java?) is close to zero. Tried following guid ...

`A title for a generic ajax data setting``

$( document ).ready(function(){ $('.status-red').click(function(){ var colonne_id = $('.status-red').attr('data-sort'); data = {sort: colonne_id , '+name': $('.search-query').val()}; ...

Modify the background color of a particular TD element when clicking a button using JavaScript and AJAX

When I click on the "Active account" button inside the designated td with the <tr id="tr_color" >, I want the value "1" to be added to the 'active_account' column in the database. I have been successful with this functionality. However, I a ...

What is the best way to showcase nested array JSON data in an HTML Table?

https://i.stack.imgur.com/OHL0A.png I attempted to access the following link http://jsfiddle.net/jlspake/v2L1ny8r/7/ but without any success. This is my TypeScript code: var viewModel = function(data){ var self = this; self.orders = ko.observableArr ...