Append additional information to the end of every .css and .jpg file

My goal is to append ?v= + Math.floor(Math.random()); at the end of every .css and .jpg file. I am still a beginner with JQuery and here is what I have managed to come up with so far.

$(document).ready(function(){

    $(something).each(function( index ) {

            //Add ?v= + Math.floor(Math.random()); to the end of each .css 
            //file and .jpg file
    });

});

I want to transform main.css to main.css?v=

Your assistance would be greatly appreciated.

Thank you

Answer №1

To update .css files, you can use the following code:

$('link').each(function (i, item) {
    item.href = item.href + '?v='+ (Math.random() * 10+i);
})

The same technique can also be used for .jpg images.

Keep in mind that each .css file will have a unique version number. If you want them all to have the same number, you can do the following:

var randomVer = (Math.random() * 10+i);

$('link').each(function (i, item) {
    item.href = item.href + '?v='+randomVer;
})

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

Ensuring the script waits for the complete loading of iframe prior to

I'm faced with an issue on the website I'm currently working on. There's a Live Chat plugin integrated on an iframe, and I need to change an image if no agents are available. Interestingly, my code works perfectly fine when tested on the con ...

Tips for beginning the process of creating a website's user interface

After initially developing my system without any styling, including bootstrap and CSS, I now find myself needing to add them. While I have reviewed the concepts on W3Schools and have a basic understanding, I am struggling with the sequence of implementat ...

Is there a way to verify if a button on a form has been clicked in an HTML file and then execute a script in Node.js?

As a newcomer to nodejs, I am currently working on one of my goals which involves sending data to a MySQL database based on the information entered into a form. I am seeking assistance on how to execute a function in nodejs when the button on the form is c ...

Would appreciate guidance on incorporating breadcrumbs into the JSP code provided below. Thank you for your help!

I need assistance with implementing breadcrumbs in these hyperlinks to enable tracking. String cat_code= fetch.getCat_code(); %> <% if(P_list!=null && P_list.size()>0) { for(int i=0;i <P_list.size();i++) { b=( Bean)P_list.get(i); % ...

Having trouble with my Bootstrap 4 navbar button - what am I doing wrong?

After conducting research online, I found myself unable to resolve my issue due to my lack of proficiency in English. I apologize for any confusion caused and would like to revisit the topic. The problem lies with my navbar toggle that is not functioning ...

Guide on Hiding the First TD Element in the Second TR Using Display None

Looking to hide the first td of the second row in the table below with a class of "visi". Any suggestions on how to achieve this? .visi{ display:none;} <table border="1" cellpadding="1"> <tr> <td class="visi" rowspan="2">__</td> ...

Unusual issue with jQuery's AJAX functionality

Utilizing jQuery AJAX, I am fetching data from a PHP page and displaying a loading GIF image in the placeholder to indicate that results are being processed. $(".project").change(function(){ $(".custName").html("<img src='/admin/images ...

Executing numerous AJAX requests using jQuery

When I make ajax calls to two different pages, one continuously sends the response while the other keeps loading and only responds when finished. This is my approach: $('.container').html('Please wait... Working : <span id="done">0&l ...

Exploring JSON and jQuery to Address Filtering Challenges

Excuse the interruption, but I need some assistance with my filters. Below is the code I'm currently working on; however, none of my attempts have been implemented yet (the dropdown menu and checkboxes remain non-functional) to make it easier for you ...

How can I address the issue of an inner content scroll bar?

I am facing an issue with the scroll bar on inner content. When I hover over an arrow on the inner content, the scroll bar appears as desired. However, it changes the content in a way that looks odd. Is there a solution to have a scroll bar on the inner co ...

External Submit button malfunctioning when attempting to submit two distinct forms

I'm currently working on a program to add items to the cart, and I need to include product attributes like colors and sizes in the process. However, I seem to be encountering an issue where only one form is submitted when using jQuery's submit(), ...

Tips for creating a more seamless box transition within HTML

I've been searching for information on this topic, but I haven't been able to find a satisfactory answer. I want to create a div that displays "Contact Us" and when clicked, smoothly reveals a layer with input fields. I know I can use JavaScri ...

Creating a design layout with Bootstrap 4: Image positioned at the center within a row, accompanied by two text blocks

I would like to center an image within a "row" class and have two text blocks on each side (left and right) of the image. Desired outcome: https://i.sstatic.net/V7KBA.png Current situation: https://i.sstatic.net/9jFsh.jpg Existing code: <sectio ...

The image is not resizing correctly

Currently, the background-image on my website displays properly when the browser occupies the entire screen. However, when I resize the browser window, the image shrinks to a certain point and then suddenly stops adjusting. Here is a visual representation ...

Exploring the process of using querySelector() to locate specific class and div IDs in JavaScript code

My objective is to make the id="myDropdownTop" trigger the corresponding drop-down menu. The problem lies in my script code, particularly the final line: ("div.dropdown-content").classList.toggle("show"); does not seem to be functioning correctly. <!D ...

Aligning a child div within a parent div by using absolute positioning for both

When creating my components dynamically using JS, I utilize position: absolute for both the parent and children elements to achieve the desired placement. But I've encountered an issue with centering a div within another div. Most solutions suggest m ...

Wordpress Sub-Menu Being Eclipsed by Banner

After upgrading my Wordpress to version 3.5.1, I noticed a problem on my site where the Submenus are loading but quickly getting hidden behind the Banner. Despite trying various modifications in the CSS file, the issue remains unresolved (and might have wo ...

Form using Ajax technology, including two drop-down menus sourced externally

Is there a way to automatically populate a second drop-down list with all models once a selection is made in the first drop-down on a form? Below is the code snippet: <form> <div class="landing_quote_left"> ...

"Utilizing CSS exclusively in conjunction with a PHP API for seamless integration

My CSS is working only when inline, and I'm struggling to track down the reason for this issue. As a beginner in web design, I am unsure of what steps to take to troubleshoot the problem. Since I cannot open the console to check for errors, what facto ...

The Php Include function is known to create unnecessary whitespace and disregard any specified styles

On one of my web pages, I am using the include() function to bring in content from another page. This external page contains both HTML and PHP code, with echoes for output. Here's an example: The page Apple.php looks like this: <html> <head ...