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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:14:16+00:00 2026-05-24T02:14:16+00:00

What I need is to iterate over the dom at some start element and

  • 0

What I need is to iterate over the dom at some start element and then go through all elements below the start element.

Here is what I was doing so far.

function iterDomFromStartElem = function(startElem, callBackFunc) {
    if (startElem !== null) {
        var items = startElem.getElementsByTagName("*");
        for (var i = 0; i < items.length; i++) {
            callBackFunc(items[i]);
        }
    }
}

The reason why I need to iterate over the dom from some start element is because our team recently got a request to implement font resizing; however, we developed are site statically with font-size in many different places using pixels. I realize that the easier approach would be to refactor the existing code, set a static font size at the root of the page, and use em’s/percentages else where, so that if the business owner wanted to have a resize control on the pages, all we would have to do is increase the font-size in one spot. This refactor would require many hours, and i have been tasked with this using the least amount of man hours.

So, then, I have a call back defined like so,

function resizeFont(startElem, scale) {
    iterDomFromStartElem(startElem, function(node) {
        // get current size of node, apply scale, increase font size
    }
}

Using this raw javascript would work but i’m having trouble getting font-size if its declared inside a css class.

I know that jquery has a css property and if I had a jquery object I could do $(this).css(….), so,

when I call callBackFunc(items[i]), how can I convert the items[i] into a jquery object so that in my call back function, I can do node.css(……)?

I guess I could do $(items[i].id), perhaps that would be the simplest.

Is there an easier way with javascript to determine the font size even if that font size is declared in a css class and that css class is attached to the element?

  • 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-05-24T02:14:18+00:00Added an answer on May 24, 2026 at 2:14 am

    Preface: I think you’re better off fixing the problem properly. You might save an hour or two now by taking a shortcut, but it’s likely to cost you in the long term.

    But re your actual question:

    how can I convert the items[i] into a jquery object so that in my call back function, I can do node.css(……)?

    If you pass a raw DOM object into $(), jQuery will return a wrapper around it. You don’t have to go via the ID.

    You can also get a jQuery instance for all descendant elements of a given starting point, like this:

    var x = $("#starting_point *");
    

    …although you’d still end up creating a lot of temporary objects if you then looped through it, like this:

    $("#starting_point *").each(function() {
        // Here, `this` is the raw DOM element
    });
    

    Here’s an example of looping all elements under a given starting point with jQuery, in this case showing their tag and id (if any) and turning them blue (live copy):

    $("#start *").each(function() {
      display(this.tagName + "#" + (this.id || "?"));
      $(this).css("color", "blue");
    });
    

    Note I said under. If you also want to include #start, the selector changes to #start, #start *.

    Here’s a complete example of increasing the font size of elements starting with (and including) a given start point, where the font size is variously set by inline and stylesheet styles (live copy):

    CSS:

    .x13 {
      font-size: 13px;
    }
    .x17 {
      font-size: 17px;
    }
    .x20 {
      font-size: 20px;
    }
    

    HTML:

    <input type="button" id="btnBigger" value="Bigger">
    <div id="start" class="x13">
      This is in 13px
      <p style="font-size: 15px">This is in 15px
        <span class="x17">and this is 17px</span></p>
      <ul>
        <li id="the_list_item" style="10px">10px
          <strong style="font-size: 8px">8px
            <em class="x20">five</em>
          </strong>
        </li>
      </ul>
    </div>
    

    JavaScript:

    jQuery(function($) {
    
      $("#btnBigger").click(function() {
        $("#start, #start *").each(function() {
          var $this = $(this),
              fontSize = parseInt($this.css("font-size"), 10);
          display("fontSize = " + fontSize);
          $this.css("font-size", (fontSize + 2) + "px");
        });
      });
    
      function display(msg) {
        $("<p>").html(msg).appendTo(document.body);
      }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create feature which will iterate through all subsites of site collection
I need to iterate over large collection (3 * 10^6 elements) in Django to
I have a JSON file which I need to iterate over, as shown below...
I need to to iterate over the files in a directory and perform the
I need to iterate through the items (strings) in a CComboBox to check which
I need to iterate through the fields on a table and do something if
I've been working on a project where I need to iterate through a collection
I need to iterate over XML items. Sample XML: <items> <name>234</name> <email></email> <phone></phone> <phone2></phone2>
I need to iterate over a recordset from a stored procedure and execute another
I need to iterate over the characters in a string to build an XML

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.