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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:43:12+00:00 2026-06-07T09:43:12+00:00

This may be hard to explain, but I have array object like this: myobject

  • 0

This may be hard to explain, but I have array object like this:

myobject = {
  "class1"     : "value1",
  "class2"     : "value2",
  "class3"     : "value3",
  ...
}

and I have script

$.each(myobject,function(i,val){
try{
    var it=0;
    $("." + i).each(function(it){
        switch($("." + i)[it].nodeName){
            case "SPAN":case "A":case "DIV":
                $("." + i).html(val);
            break;
            case "INPUT":
                switch($("." + i).attr("type")){
                    case "submit":
                        $("." + i).attr("value",val);
                    break;
                    case "text":case "password":case "email":
                        $("." + i).attr("placeholder",val);
                    break;
                }
            break;
            case "IMG":
                $("." + i).attr("alt",val);
                $("." + i).attr("title",val);
            break;
        }
    });
}catch(err){
    // Nothing
}
});

Effect of code for span, a, div should be this:

Was:  <span class="class1"></span>
Is:   <span class="class1">value1</span>

and for input where type=submit, it should be this:

Was:  <input type="submit" class="class2" />
Is:   <input type="submit" class="class2" value="value2" />

Code effects for span, a, div and input[type=submit], but this won’t set placeholders. Why?

  • 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-07T09:43:13+00:00Added an answer on June 7, 2026 at 9:43 am

    What you’re trying is an overly complicated way to do what you want. Just use the power of the jQuery selector to your advantage to filter by tag type:

    $.each(myobject, function(k, v){
        $('span.' + k + ', ' +
          'a.' + k + ', ' +
          'div.' + k).html(v);
    
        $('input.' + k + '[type="submit"]').val(v);
    
        $('input.' + k + '[type="text"], ' +
          'input.' + k + '[type="password"], ' +
          'input.' + k + '[type="email"]').attr('placeholder', v);
    
        $('img.' + k).attr('title', v)
                     .attr('alt', v);
    });
    

    EDIT:

    See demo

    (perhaps you can figure out from looking between the demo and your code what’s different and why it’s not working)

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

Sidebar

Related Questions

This may sound like a very generic question but here it goes. I have
This may have been asked before, but it's really hard to search for terms
This may be a little hard to describe since I don't have a sample.
This may be a stupid question but I have a code with the following
This may be have a better name than custom tab completion, but here's the
This may be a duplicate of some other question, but it's hard to search
This is hard to explain but if you go here: https://developers.facebook.com/docs/reference/api/ You will see
This may be an obvious thing for most, but I am having a hard
Hard to explain this one, but here it goes: I'm using jQuery to add
This may not really sound hard to do but it is currently killing me.

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.