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?
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:
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)