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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:50:18+00:00 2026-05-14T06:50:18+00:00

I am trying to create a function that given a divid, and a list

  • 0

I am trying to create a function that given a divid, and a list of classes, will then do some text replacing inside them.

Having learned of how Firefox Dom is handling text nodes differently, I read that I had to use javascript to loop through the elements, sibling to nextSibling.

The last obstacle I had in my script, of which you see a small portion of, is getting the classname. I need the class name so that I can filter down what content get’s text replaced.

Having looked all the answers, and with the help of a co-worker named Ryan at work, we have redone this in jquery.

        $(divid).find(".status_bar").each( function() {
        var value = $.trim($(this).text());
        // if value is not defined thru browser bugs do not replace
        if (typeof(value) != 'undefined') {
            // it is a text node. do magic.
            for (var x = en_count; x > 0; x--) {
                // get current english phrase
                var from = en_lang[x];
                // get current other language phrase
                var to = other_lang[x];
                if (value == from) {
                    console.log('Current Value ['+value+'] English ['+from+'] Translation ['+to+']');
                    value = to;
                    $(this).attr('value', to);
                }
            }
        }
    });

This currently works in all areas, except in the replacing of text.

The reason I had originally with doing this in jQuery, had to be not sure I could loop thru elements, and avoid the problem with firefox and text nodes.

I am doing a loop of all elements inside a div, and I now need to get the classname of the element that I am looping by.

Then i can check if the current element’s class is one, I need to do something with…

 // var children = parent.childNodes, child;
    var parentNode = divid;

    // start loop thru child nodes
    for(var node=parentNode.firstChild;node!=null;node=node.nextSibling){

    var myclass = (node.className ? node.className.baseVal : node.getAttribute('class'));

    }

But this code for getting the classname only get’s null values.

Any suggestions?

For those of you who are trying to figure out what the whole point is, read this JavaScript NextSibling Firefox Bug Fix I have code that does my language translation that works in Google Chrome and IE. But when I use it in Firefox, and try to translate div content after ajax has loaded it, it fails because of the whitespace issue.

I really don’t have a preference of jQuery or Pure Javascript, I just want a working solution.

Thank you all for being patient. I personally thought I was extremely clear in my description, I apologize if it wasn’t. I wasn’t trying to be obscure or make it difficult to get help. But please don’t insult me, by implying I am trying to make it unclear.

Thanks.

  • 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-14T06:50:18+00:00Added an answer on May 14, 2026 at 6:50 am

    Hm… You have jQuery but don’t use it?

    $(divid).children(".yourSpecialClassName").each( function() {
      doSomethingWith(this);
    });
    

    To get the CSS class attribute value, this will do:

    $(divid).children().each( function() {
      alert(this.className);
    });
    

    Based on the function you posted now, you want this:

    $(divid).find(".status_bar").each( function() {
      $(this).text( function(i, text) {
        var x = $.inArray(en_lang, $.trim(text));
        if (x > -1) {
          console.log('Current Value ['+text+'] English ['+en_lang[x]+'] Translation ['+other_lang[x]+']');
          return other_lang[x];
        }
        return text;
      });
    });
    

    And please, don’t ever use “do magic” as a comment again. This is incredibly lame.


    EDIT. This can be made much more efficient (superfluous console.log() removed):

    $(divid).find(".status_bar").each( function() {
      // prepare dictionary en_lang => other_lang
      var dict = {};
      $.each(en_lang, function(x, word) { dict[word] = other_lang[x]; });
    
      $(this).text( function(i, text) {
        var t = $.trim(text);
        return (t in dict) ? dict[t] : text;
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When you double click on a .net .exe assembly: Windows'… May 14, 2026 at 7:01 pm
  • Editorial Team
    Editorial Team added an answer Got it: adobe public class TextBlock_createTextLineExample extends Sprite { public… May 14, 2026 at 7:01 pm
  • Editorial Team
    Editorial Team added an answer If you check $stmt->errorInfo() you will actually find that your… May 14, 2026 at 7:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.