Find and target all CSS elements that have the property of "display: inline

Can the CSS be searched by property:value instead of selector/attribute? Or does this require parsing through a server script?

If it is achievable, I am considering developing a script that will automatically include the IE7 hack when the selector contains: display: inline-block because I find it tedious to keep writing *display: inline; zoom: 1;

Answer №1

If you want to add the style directly to the element for filtering purposes, you can use the following approach:

Method 1

$("[style*='inline-block']");

The code above may not capture elements if the style is computed using CSS. In this scenario, you can utilize the following method.

Method 2

$('*').filter(function() {
    return $(this).css('display') == 'inline-block';
});

For instance, consider the HTML snippet below.

<div style="display: inline-block"></div>
<div class="someClass"></div>

Method 1 will only retrieve the first item, while Method 2 will fetch both.

Answer №2

If you want to execute code only when an element is styled as inline-block, you can use the following script:

$("body *").each(function (i) {
    if ($(this).css('display') == "inline-block") {
        // Do something for inline block elements
        this.style.color = "blue";
        alert($(this).css('display'));            
    }
});

For a working example, check out the jsfiddle http://jsfiddle.net/nevtn/.

Below is the full script needed:

$(document).ready(function(){

if ($.browser.msie  && parseInt($.browser.version, 10) === 7) {
    $("body *").each(function (i) {
        if ($(this).css('display') == "inline-block") {
            // Update style for inline block elements in IE7
            $(this).css({'display':'inline', 'zoom':'1'});  
        }
    });
}

});​

Demo showcasing how it works in a simulated IE7 environment: http://jsfiddle.net/nevtn/5/

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

Conceal list items by clicking elsewhere on the page

Currently, I am facing an issue with my search user functionality. Whenever a user clicks anywhere else on the page, the list of results does not disappear unless the user manually deletes all the words they have typed. This behavior is not ideal and despi ...

Encountering difficulties triggering the click event in a JavaScript file

Here is the example of HTML code: <input type="button" id="abc" name="TechSupport_PartsOrder" value="Open Editor" /> This is the jQuery Code: $('#abc').click(function () { alert('x'); }); But when I move this jQuery code to a ...

Use the $.get() method in JavaScript to send a parameter to my controller function

My objective is to showcase the event details in a modal. To achieve this, I am running a JavaScript script that calls the "GetEventsDetails" method in my "Event" controller with the event ID. While debugging in Chrome, I can see the ID being passed corre ...

Is there a native horizontal divider available in Bootstrap 4?

Is there a predefined horizontal divider in Bootstrap 4? I currently have this: <style type="text/css> .h-divider{ margin-top:5px; margin-bottom:5px; height:1px; width:100%; border-top:1px solid gray; } </style> However, I would prefer t ...

Ways to highlight a form field only when there is data in my variable

For the validation of email addresses in my form, I have been using a combination of php and ajax. The process involves sending the email value via jQuery to my php file and displaying a message if the email is found in the database. While my code function ...

Tips for sending a selected option value to jQuery via AJAX using the name attribute

Is there a way to send the section option value using ajax, but only for selection and checkboxes? The issue I'm facing is that when posting, the section and checkbox appear as undefined. Thanks in advance. PHP Code <?php $parameters = new P ...

Enhancing Symfony's performance through optimized Ajax response time

When using Symfony2, I am experiencing differences in loading times for AJAX requests between development and production environments. In development, it takes 1 second to load, while in production it only takes 500 milliseconds for a simple call: Here is ...

Send the result of a successful AJAX request to a partial view

I have added these lines of code, where the success function returns data in the form of [object Object], with attributes like Name, Category, and Description. $.ajax({ url: rootUrl + 'Admin/EditRSS', type: "GET", data: { ...

"Enhancing Website Styling with Twitter Bootstrap's Border

Recently delving into the realm of Twitter Bootstrap, I find myself pondering on the best approach to incorporate a border around a parent element. Consider this scenario: <div class="main-area span12"> <div class="row"> <div cl ...

A method for expanding the menu upwards to make room for newly added items

Looking at the images below, I have a menu that needs new items added to it while maintaining the position of the lower-left corner. Essentially, each time an entry is added, the menu should expand upwards from "the upper-left corner" while keepi ...

Is it possible to add a border to both the tbody and td

I currently have a table that is organized with tbody elements to group rows together. In order to create a grid-like structure, I applied borders to each individual td element within the tbody. However, I also desire to show that the tbodies themselves ar ...

Animated mosaic pattern menu design

Is there a way to achieve this effect with a sketch? Note: I would like to add hover animation to the borders if possible. I attempted to do it using the following code: clip-path: polygon(0 0, 100% 0, 92% 86%, 6% 100%); However, the shapes created by ...

Adjust the JSON format that is retrieved from an Ajax call

I am working with a JQuery plugin that includes the following code snippet: transformResult: function(response, originalQuery) { } Within this function, I have the task of converting Json data from the originalQuery to the response format: [ { "Id": ...

Guide on obtaining an obscure style guideline in MS Edge using JavaScript

If you are looking to utilize the object-fit CSS rule, keep in mind that it is not supported in MSIE and MS Edge Browsers. While there are polyfills available for IE, none of them seem to work in Edge from my experience. For instance, the polyfill fitie b ...

SyntaxError: Unexpected symbol

I have an issue with the following code: let op = data.map(({usp-custom-90})=> usp-custom-90 ) When I run it, I encounter the following error: Uncaught SyntaxError: Unexpected token - I attempted to fix it by replacing the dash with –, but t ...

Utilizing the hcSticky plugin for creating a scrolling effect on webpage content

I'm attempting to utilize the JQuery plugin, hcSticky, in order to achieve a scrolling effect on my fixed content. However, I seem to be encountering some difficulty getting it to function properly. What could I possibly be doing incorrectly? JSFIDDL ...

Accessing the facebox feature within a dropdown menu

Looking for assistance in creating a function to open a facebox when an option from a drop down list is selected. Here is what I have so far: <select><option value="www.google.com/" id="xxx"></option></select> In the header sectio ...

Exploring nested JSON information through jQuery's AJAX call

I am encountering an issue with accessing JSON data using a jQuery AJAX request in JavaScript. I keep receiving a 'Cannot read property [0] of undefined' error in the console of Google Chrome. Despite trying different approaches, such as referrin ...

Out of the blue, the CSS functionality in my React app completely ceased to

I've been developing this website using React and Material UI, and I chose to implement standard CSS for styling. However, after closing my code editor and reopening it, some parts of the CSS do not seem to be loading properly. I'm completely puz ...

Step-by-step guide on incorporating jQuery and Bootstrap into your project post npm installation

As I progressed in my coding journey, I decided to level up my skills by moving away from using CDNs and exploring new tools. One of the tools I delved into was NPM, mastering the basics like installation and updating. However, I found myself stuck when it ...