Refreshing CSS-Element-Queries following an ajax request

I’ve been utilizing css-element-queries from the https://github.com/marcj/css-element-queries repository to tailor styles based on an element's dimensions. However, I encountered an issue when dynamically adding elements via ajax calls. The new elements loaded through ajax are not being styled correctly, presumably because they are not present during the execution of the css-element-queries script. As this script runs automatically on window.load, I am unsure how to ensure it runs again after a successful ajax call. Since I’m using jquery, any jquery-specific solutions would be greatly appreciated.

Answer №1

There is a solution to the css-element-queries issue.

More information can be found here

To trigger the window.load event forcibly, you can use:

dispatchEvent(new Event('load'));

However, this method is outdated and may cause your Ajax functionality to enter into a loop, especially if it relies on the onload event. An alternative approach for IE Old School Netscape 2 is to use the document.write method.

document.write("<script src='ajax.js'><"+"/"+"script>");

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

Leverage the power of puppeteer alongside webpack

Struggling to make puppeteer work with webpack? Despite adding it to package.json and configuring webpack.dev, the 'launch' function still throws errors. Here's what I've tried: Installed dependency in package.json: npm i puppeteer In ...

Issues with looping Jquery ajax请求

Is there a bug in the code? Here are some examples: for(i=0;i<2;i++){ $.ajax({ url : 'process.php', type: "POST", data : "abcd", success : function(data){ alert(i); } }) } or for(i=0;i<2;i++){ $.post("proc ...

Simple server using node.js and express to host an HTML file and associated resources

I am currently experimenting with frontend development and need a basic web server to quickly start projects and serve files. Specifically, I have one index.html file along with some css/js/img files. I decided to work with Node.js and Express for this pur ...

Is there a problem with the alignment of

<s:form id="inputThresholdForm" name="inputThresholdForm" theme="simple"> <table border="0" class="display-table" cellspacing="2" cellpadding="2" height="100%" width="100%"> <tr> <td colspan= ...

Convert angular-tree-component JSON into a suitable format and dynamically generate checkboxes or radio buttons

Currently, I am using the angular-tree-component for my treeview implementation. You can find more details about it in this reference link. The array structure I am working with is as follows: nodes = [ { id: 1, name: 'root1', ...

appending a set of parameters to a website address

I am currently developing an app in a Node/Express/Jade environment. Imagine that I launch my app and navigate my browser to the following URL: /superadmin/?year=2012 Upon reaching this page, I encounter a list of objects sorted in a default order. Ther ...

json How to retrieve the first index value in jQuery

As part of my Ajax loop, I am successfully generating JSON and iterating through the results. My goal is to extract only the first index value of JSON which is name. In jQuery, I have the following code: PHP $jsonRows[] = array( "name" => ...

Challenges with AJAX Post Data Demonstration

There seems to be an issue that I can't quite figure out - not sure if it's a bug or just my mistake. If you have expertise in AJAX, maybe you could provide some insight without requiring knowledge of ENYO. In the example of DATA in ENYO, there ...

Is there a way to incorporate the ::after or ::before pseudo-elements into an image tag?

While working on my project, I attempted to incorporate the ::after tag (I had used ::before as well) for an image within an img tag. However, I am facing difficulties as it doesn't seem to be working. Any advice or guidance would be greatly appreciat ...

From JSON object to HTML table: converting structured data into a user

I'm currently facing a challenge when trying to iterate through JSON data retrieved from an API and display it in an HTML table. After parsing the original JSON, I accessed its elements as follows: JSON (data retrieved from API): {"PrekesID" ...

An error has been noticed: "Unexpected token o" - Syntax is not

I'm currently developing a web application and have encountered an issue: $("#post").click(function () { var u = $('#u').val(); var j = $('#j').val(); $.post("http://www.myweb.php", { u: u, j: ...

Creating an automated sequence of $http requests to sequentially retrieve JSON files with numbered filenames in Angular 1.2

I have a series of JSON files (page1.json, page2.json, etc.) that store the layout details for our website pages. Initially, I would load each page's data as needed and everything was functioning smoothly. However, it is now necessary for all page da ...

Is it possible to exclusively focus on the specified data attributes?

Is there a method to specifically target the 'data-season' attribute with the value "winter"? This is my HTML: <li data-season="summer">summer <ul class="groups"> <li data-item="beach">beach</li> <li data-item ...

Angular JavaScript does not take effect on elements inserted into ui-view

When transferring the code from main.html to index.html, the javascript functions smoothly. The click function successfully triggers the ripple effect. Link: Ripple Click Effect Google Material Design However, upon extracting the code to main.html and in ...

Switching between components in Vue.js

I am a beginner with vue.js and I have encountered a challenge. On my page, I display a list of people with an 'Edit' button next to each person's details. My goal is to switch to another page when the Edit button is clicked, where I can edi ...

Tips for displaying the message "{"POWER":"ON"}" within the else if statement (this.responseText == ({"POWER":"ON"})) {

Hey everyone, I'm trying to adjust the color of a button on my webpage based on the response I receive from this.responseText. I understand the JSON response, but for some reason, I can't seem to incorporate it into my code. If anyone could lend ...

Exploring the power of Ajax requests in customizing AdminOrdersController in PrestaShop 1.6

I have come across similar topics, but they did not provide the solution I need. PS: 1.6.1.1 Overview: Is there a "magic" code that needs to be included in the AdminOrdersController override for it to handle ajax requests (jQuery) correctly? Details: I ...

convert a JSON object to an array using jQuery

Can anyone help me with converting an object into an array using jQuery? [["20"],["30"],["45"],["54"],["33"],["15"],["54"],["41"]] I am looking to achieve an array output like this: [20,30,45,54,33,15,54,41] Any suggestions on how to accomplish this? ...

Using JavaScript to modify a section of an anchor link attribute

I am looking to dynamically update part of the URL when a specific radio button is selected. There are three purchase links, each representing a different amount. After choosing an animal, I need to select one of the three amounts to spend. How can I modi ...

Customize Popover Color in SelectField Component

Looking to customize the SelectField's popover background color in material-ui. Is this possible? After exploring the generated theme, it seems that there is no option for configuring the selectField or popover. Attempted adjusting the menu's ba ...