Struggling with Mootools selectors

Take a look at this HTML snippet:

<div id="link-thumbs-list">
<img src="image.php?f=http://www.jetphotos.net/trans.gif&amp;h=72&amp;w=128" />
<img src="image.php?f=http://www.jetphotos.net/logo-nb.jpg&amp;h=72&amp;w=128" />
<img src="image.php?f=http://www.jetphotos.net/trans.gif&amp;h=72&amp;w=128" />
</div>

I'm trying to extract the file URLs (f=) and use them in the src attribute of each image tag. Any suggestions on how to accomplish this? Thank you!

Answer №1

Simply put:

var imageList = document.getElementsByClassName("link-thumbs-list");
var urls = [];

for (var i = 0; i < imageList.length; i++) {
    var src = imageList[i].getElementsByTagName("img")[0].getAttribute("src")
    urls.push(src.replace("image.php?f=", "").split("&")[0]);
}

console.log(urls);

This will display the following URLs:

["http://www.jetphotos.net/trans.gif", "http://www.jetphotos.net/logo-nb.jpg", "http://www.jetphotos.net/trans.gif"]

Answer №2

$$("#thumbs-list-link img").each(function(element) {
    var match = element.get("src").match(/f=([^&]*)&/);
    if (match && match[1]) {
        element.set("src", match[1]);
    }
});

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

Transferring data between views in MVC5

Currently in the process of developing an event management system where I need to create events and generate multiple tickets for each event. Utilizing c# and ASP.NET MVC, I have set up the following model classes; public class Event { public int Even ...

Incorporating an Edit button with an icon into a react-bootstrap-table2

Is there a way to insert buttons in the Edit column of my table so I can easily edit a row? I believe there should be a method to personalize the column and incorporate icons as shown in the example image. Sample Image of What I want to do: import React ...

Tips for acquiring the newest router in an angular environment

Is there a way to retrieve and store the URL of the latest router that the user has visited in local storage? Any suggestions would be greatly appreciated. Thank you! ...

Looking to convert this single object into an array of objects within VueJS

So, I've encountered a bit of a pickle with the data from an endpoint that I need to format for a menu project I'm working on. It's all jumbled up and not making much sense right now. Any assistance would be greatly appreciated! This is the ...

Using jQuery to dynamically render unordered lists from JSON data

Struggling to create a dynamic unordered list with multiple nested levels? Finding it difficult to render the necessary markup for future functionality? Take a look at the HTML structure I've created on this jsfiddle link: <ul class="nav nav-sideb ...

What benefits does minifying server-side nodejs code provide?

Is there a benefit to minifying Node.js code in the same way as minifying JavaScript, particularly for reducing size and improving network download speed? When a file is required in Node.js, it is loaded into V8 and processed and stored in memory in some f ...

What is the best way to give precedence to non-auto capitalization in input fields on the Input Component from Material UI, especially when using iPads?

The issue I'm encountering is specific to Material UI and IPad, requiring a change in the component used from MUI. Currently, I am utilizing the Input component from Material UI. Upon clicking on the input, the IPad keyboard opens and automatically ...

Encountering an issue when attempting to construct the project: it asks for callback functions, but instead received an [

I'm currently facing an issue while trying to access a function that is crucial for updating some database values. Whenever I attempt to build the project, I encounter the following error: Error: Route.post() requires callback functions but got a [ ...

The image slideshow on W3 Schools displays images in a stacked formation

Utilizing this code snippet from W3 Schools to incorporate an image slideshow into my web project. However, upon page load/reload, the images appear stacked vertically rather than horizontally (one above and one below). The slideshow functions properly aft ...

Connecting two COTURN servers for seamless communication

Currently, I have a total of 5 webRTC peers connected through the COTURN server (turnServer1). These peers are all behind symmetric NAT, requiring the use of the TURN server to establish connections. However, due to the media streams with audio and video b ...

Modifying an object's value before pushing it into an array in JavaScript

I've been struggling to find the right keyword to search for my issue. I've spent hours trying to figure out what's wrong, but it seems like a simple case of pushing an object into an array. The problem arises when I try to log the values of ...

Conceal the element at all times

I'm facing a challenge with a paragraph element that is dynamically filled with content using Javascript. I need to hide the element whenever it doesn't have any text within it. However, I want to avoid using setTimeout or setInterval for this ta ...

Weather-js efficiently retrieves particular information from the displayed content

I'm currently utilizing weather-js to retrieve weather information based on a user's location determined by their IP address. My main question revolves around streamlining the output data in the console. Unfortunately, this API lacks documentatio ...

Retrieving JSON data using Jquery (undefined)

When attempting to retrieve a value from JSON data, I am receiving 'undefined'. $.get( baseURL + 'vacation/show/' + name_surname, function( data ) { alert(data); // returns [{"id":"1","title":"Testas","start":"2015-03-04","end":"20 ...

Developing custom functions in ejs for individual posts

In my blog, I have a feed where all users' posts are displayed dynamically using ejs. There is a comment section that remains hidden until the user clicks the comments button. Below is a snippet of my ejs file: <% posts.forEach(post => { %> ...

Issues with the execution of Jquery function

Hey guys, take a look at my code: //Additional Jquery codes // display_popup_crop : revealing the crop popup function display_popup_crop(link) { alert("show_popup_crop function is triggered!"); // changing the photo source $('#cropbox&a ...

When you input text into a contenteditable div, it automatically gets placed inside a span element instead of being placed

I'm having an issue with my contenteditable div. Whenever I click the button, a span is inserted into the div. However, when I start typing, the text goes inside the span instead of outside it: jQuery(document).ready(function($) { let input = $(" ...

Error: Cannot assign type 'null' to click event type Array. I have not been able to locate a solution to my issue in other related queries

Can someone assist me with my latest Angular project? I encountered an issue with the (click)="onOpenModal(null, 'add')" function call. Since it's meant to open a modal without an existing employee, I passed in null as a placeholde ...

Tips for enabling autofocus in mat-select列表。

I am working on an angular project where I am using Angular Material and a mat-select element. In my form, the mat-select is the first element, and I want to set auto-focus on it when the page loads. However, I have been facing some difficulties achieving ...

I am experiencing an issue with the checkbox in my React app where the state is not updating after it has been

I am currently building a todo app using React, but I'm encountering an issue where nothing happens when I click the checkbox. I've provided my code below: App.js import './App.css'; import React from 'react' import TodoItem ...