Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:34:53+00:00 2026-06-18T12:34:53+00:00

Let’s suppose I want to dynamically add CSS rules that are tied to a

  • 0

Let’s suppose I want to dynamically add CSS rules that are tied to a media condition. For example, something like following:

@media only screen and (min-device-width : 500px){
    .someClass: {
        color: blue;
    }
}

A logical step would be to use JavaScript to check the validity of the media query and insert the rule if the test passes. Something like following:

if(matchMedia(only screen and (min-device-width : 500px))){
    $('.someClass').css('color', 'blue');
}

The drawback being that the rule would NOT be responsive. If I change the screen size, the blue color will not change accordingly. I can add a listener to screen size changes but I think it’s a bit overkill.

My question is: is there a way to add a responsive rule via Javascript or JQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:34:54+00:00Added an answer on June 18, 2026 at 12:34 pm

    You want to hear about enquire.js:

    enquire.register("screen and (max-width:1000px)", {
    
        match : function() {},      // REQUIRED
                                    // Triggered when the media query transitions 
                                    // *from an unmatched state to a matched state*
    
        unmatch : function() {},    // OPTIONAL
                                    // If supplied, triggered when the media query transitions 
                                    // *from a matched state to an unmatched state*.
    
        setup : function() {},      // OPTIONAL
                                    // If supplied, a one-time setup function 
                                    // triggered when the handler is first registered.                           
    
        deferSetup : true,          // OPTIONAL, defaults to false
                                    // If set to true, defers execution the setup function until
                                    // the media query is first matched. Setup is still triggered just once.
    
        destroy : function() {}     //OPTIONAL
                                    // If supplied, triggered when a hander is unregistered (covered later). 
                                    // Enables you to provide lifecycle to responsive widgets. 
                                    // Put cleanup logic here.
    
    }).listen(); // More on this next
    

    [from the docs]

    EDIT: if you want to add a pure CSS rule via js [without relying on a listener], I think it is not possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I've got a collection of 10 million documents that look something like
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let me explain best with an example. Say you have node class that can
Let's suppose that we have multi-site CMS and every website in this CMS having
Let's say I want to write a function that validates an email address with
Let's say that each Product has a category. I want to ask the Users
Let me give an example and try to explain what I want to ask:
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let me try to explain by example. Say website is hosted at example.com (NOT
Let's say that I have a SQLite database that I create in a separate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.