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 7972403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:51:17+00:00 2026-06-04T07:51:17+00:00

I am having trouble deleting rules from the stylesheet object due to ever changing

  • 0

I am having trouble deleting rules from the stylesheet object due to ever changing indexes.

I have this function:

function delete_styles(delete_array){

    console.log(delete_array); // ["0,0", "0,1", "0,2", "0,6", "0,7", "0,8", "0,9", "0,10", "0,14", "0,15", "0,16"]

    for(var i in delete_array){

        var pair = delete_array[i].split(',');
        var p1 = parseInt(pair[0]);
        var p2 = parseInt(pair[1]);

        document.styleSheets[p1].deleteRule(p2);

    }
}

However, as soon as I delete (0,0), the index (0,1) is invalid because it becomes (0,0)!

I can’t just use a counter and take a way an incrementing amount each time because there may be larger gaps in the CSS rules.

Any help on the logic here?

  • 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-04T07:51:18+00:00Added an answer on June 4, 2026 at 7:51 am

    Consider starting from the end, instead of the beginning, and work your way down. That way, the there are no styles falling on the spot you just deleted.

    Also, when using the array, do not use for in. use the usual for loop (or while) instead.

    var i = delete_array.length;
    while(i--){
        var pair = delete_array[i].split(',');
        var p1 = parseInt(pair[0]);
        var p2 = parseInt(pair[1]);
    
        document.styleSheets[p1].deleteRule(p2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble deleting this (a specific 'event') from the following javascript object,
I am having some trouble deleting documents from Solr index. I use following code:
Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =
I'm having trouble deleting/removing an item from an Array in jQuery. I've run the
I am having trouble deleting multiple konkurrancers with checkboxes. I get this error in
I am having trouble deleting my pointers that I have created. The program creates
I'm having some trouble deleting an item from a collection inside a model when
Having trouble with this jQuery function: $(#content).siblings().each(function(i){ heightOfSiblings = heightOfSiblings + this.outerHeight(); }); Error
I'm having trouble deleting images from a mysql database using php. The addition of
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder

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.