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

  • Home
  • SEARCH
  • 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 8577039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:04:24+00:00 2026-06-11T20:04:24+00:00

So I’m doing a redesign for a site with an unhelpful CMS where I

  • 0

So I’m doing a redesign for a site with an unhelpful CMS where I don’t have full access to the markup (or ftp access). There’s a node in particular which is hindering my progress significantly – its written with inline style & no class or ID and I have to change it (not remove it). Its looking like:

<div style="background-color: blue">
<div class="editablecontent">
(stuff I can edit in the CMS goes here)
</div>
</div>

I don’t think getElementsByClassName is going to work here? but what sort of works is the very ugly defining an empty div with an ID then and document.getElementById.parentNode.parentNode.style.backgroundColor=”white” which is obviously filthy and doesn’t work in IE anyways and I need IE8 support (at least). I am not using a framework but do have access to the header.

Thanks in advance.

  • 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-11T20:04:25+00:00Added an answer on June 11, 2026 at 8:04 pm

    Assuming this content is unique in your document (e.g. there’s only one of them), you can use this to find it:

    function changeColor() {
        var divs = document.getElementsByTagName("div");
        for (var i = 0, len = divs.length; i < len; i++) {
            if (divs[i].style.backgroundColor === "blue" && 
              divs[i + 1] && 
              divs[i + 1].parentNode === divs[i] &&
              divs[i + 1].className === "editablecontent") {
                divs[i].style.backgroundColor = "white";
                return;
            }
        }
    }
    

    This does the following steps:

    1. Get all divs in the document
    2. Look for one with backgroundColor set to blue with an inline style setting
    3. When you find one check to see if there is another div after it
    4. If that next div is a child
    5. If that next div has a className of "editablecontent"
    6. Then, change its background color.

    If you wanted any further checks based on other criteria to make sure you were finding the right object, you could add those to the logic, though these checks are all you have disclosed to us.

    Working example: http://jsfiddle.net/jfriend00/NmxUn/


    Another approach is to use getElementsByClassName and install a polyfill like this one to make it work in older browsers:

    // Add a getElementsByClassName function if the browser doesn't have one
    // Limitation: only works with one class name
    // Copyright: Eike Send http://eike.se/nd
    // License: MIT License
    
    if (!document.getElementsByClassName) {
      document.getElementsByClassName = function(search) {
        var d = document, elements, pattern, i, results = [];
        if (d.querySelectorAll) { // IE8
          return d.querySelectorAll("." + search);
        }
        if (d.evaluate) { // IE6, IE7
          pattern = ".//*[contains(concat(' ', @class, ' '), ' " + search + " ')]";
          elements = d.evaluate(pattern, d, null, 0, null);
          while ((i = elements.iterateNext())) {
            results.push(i);
          }
        } else {
          elements = d.getElementsByTagName("*");
          pattern = new RegExp("(^|\\s)" + search + "(\\s|$)");
          for (i = 0; i < elements.length; i++) {
            if ( pattern.test(elements[i].className) ) {
              results.push(elements[i]);
            }
          }
        }
        return results;
      }
    }
    

    And, then you could simply do this, even on older versions of IE:

    var items = document.getElementsByClassName("editablecontent");
    if (items.length) {
        items[0].parentNode.style.backgroundColor = "white";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.